﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Collections;

namespace TCCCompiler
{
    public class LineParser
    {
        List<string> CodeLines;
        List<string> m_Tokens;

        string[] m_TypeOfStatement;
        Regex m_Identifiers;

        public TreeNode root;
        public TreeNode CurrentNode;
        public TreeNode TempNode;

        List<Token> token = new List<Token>();
        Token CurrentToken;
        TreeNode statementNode;
        TreeNode tokenNode;
        Stack m_CurledBrackets = new Stack();
        Stack m_DeclaredIntegers = new Stack();
        Stack m_DeclaredCharacters = new Stack();
        Stack m_DeclaredIntegersArray = new Stack();
        Stack m_DeclaredCharacterArray = new Stack();
        Stack m_DeclaredHashtables = new Stack();
        Stack m_AssignedIntegers = new Stack();
        Stack m_AssignedCharachters = new Stack();
        int[] m_CurrentScopeNewIntegerCounter = new int[100];
        int[] m_CurrentScopeNewCharacterCounter = new int[100];
        int[] m_CurrentScopeNewIntegerArrayCounter = new int[100];
        int[] m_CurrentScopeNewCharacterArrayCounter = new int[100];
        int[] m_CurrentScopeNewHashtableCounter = new int[100];
        int CurrentScope = 0;
        TreeNode[] CurrentBlockNode;
        int CurrentBlockNodeIndex = 0;
        List<string> m_DoubleExpressionOperatorsBorA = new List<string>(new string[2] { "++", "--" });
        List<string> m_DoubleExpressionOperatorsA = new List<string>(new string[4] { "+=", "-=", "*=", "/=" });
        List<string> m_SingleConditionOperatorsBwExp = new List<string>(new string[2] { "<", ">" });
        List<string> m_DoubleConditionOperatorsBwExp = new List<string>(new string[4] { "<=", ">=", "!=", "==" });
        List<string> m_ConditionOperators = new List<string>(new string[6] { "<=", ">=", "!=", "==", "<", ">" });
        List<string> m_DoubleConditionOperatorsBwCond = new List<string>(new string[2] { "&&", "||" });
        List<string> m_String_Delimeters = new List<string>(new string[12] { "++", "--", "<=", ">=", "!=", "==", "+=", "-=", "*=", "/=", "&&", "||" });
        char[] m_String_Delimeters_Start = new char[10] { '+', '-', '=', '!', '<', '>', '|', '&', '*', '/' };
        List<char> m_Char_Delimeters = new List<char>(new char[16] { '+', '-', '*', '/', '%', '=', '<', '>', ';', '(', ')', '[', ']', '.', ';', ',' });
        List<string> SplittedLine = new List<string>(); //splitted by "++" and "+"
        List<string> CharSplittedTokens = new List<string>(); // splitted by "+"
        Regex m_IntegerConstants = new Regex(@"[-]?[0-9]+(\.[0-9]+)?(E[-]?[0-9]+(\.[0-9]+)?)?");
        Regex m_CharacterConstants = new Regex("\'[a-zA-Z0-9]\'");
        Queue<LiteralTable> LiteralTableStack = new Queue<LiteralTable>();
        public Queue LiteralTableDataName = new Queue();
        public Queue LiteralTableDataType = new Queue();
        LiteralTable lt = new LiteralTable();
        public TreeNode root2;
        List<string> NewDataLines;

        public LineParser(List<string> Lines, TreeNode node, List<string> DataLines, TreeNode NewDataNode)
        {
            for (int i = 0; i < 100; i++)
            {
                m_CurrentScopeNewCharacterCounter[i] = 0;
                m_CurrentScopeNewIntegerCounter[i] = 0;
                m_CurrentScopeNewCharacterArrayCounter[i] = 0;
                m_CurrentScopeNewIntegerArrayCounter[i] = 0;
                m_CurrentScopeNewHashtableCounter[i] = 0;
            }
            m_Identifiers = new Regex(@"^[a-zA-Z][0-9a-zA-Z]*");
            m_TypeOfStatement = new string[Lines.Count];
            CodeLines = Lines;
            NewDataLines = DataLines;

            InitializeDataTree();
            TempNode = CurrentNode;
            for (int i = 0; i < NewDataLines.Count; i++)
                if (NewDataLines[i] != null)
                    DetectDataBlock(NewDataLines[i], i);
            NewDataNode = root2;

            InitializeTree();
            TempNode = CurrentNode;
            for (int i = 0; i < Lines.Count; i++)
                if (Lines[i] != null)
                    DetectStatement(Lines[i], i);
            node = root;
        }
        void InitializeDataTree()
        {
            root2 = new TreeNode("Data");
            CurrentNode = root2;
        }
        void InitializeTree()
        {
            root = new TreeNode("Code");
            CurrentNode = root;
            statementNode = root;
            CurrentBlockNode = new TreeNode[CodeLines.Count + 2];
            CurrentBlockNode[0] = root;
            CurrentBlockNodeIndex++;
        }
        int IndexStringContains(string str, List<string> splitters)
        {
            for (int i = 0; i < str.Length - 1; i++)
            {
                for (int j = 0; j < splitters.Count; j++)
                {
                    if (str.Substring(i, 2) == splitters[j])
                        return i;
                }
            }
            return -1;
        }
        //int FindFirstStringOperator(string str, string[] splitters)
        //{
        //    for (int i = 0; i < str.Count - 1; i++)
        //    {
        //        for (int j = 0; j < splitters.Count; j++)
        //        {
        //            if (str.Substring(i, 2) == splitters[j])
        //                return i;
        //        }
        //    }
        //    return -1;
        //}
        int IndexCharContains(string str, List<char> splitters)
        {
            char[] CharArray = str.ToCharArray();
            for (int i = 0; i < CharArray.Length; i++)
            {
                if (CharContains(splitters, CharArray[i]))
                {
                    return i;
                }
            }
            return -1;
        }
        bool CharContains(List<char> CharArray, char ch)
        {
            for (int i = 0; i < CharArray.Count; i++)
                if (CharArray[i] == ch)
                    return true;
            return false;
        }
        string StringSeparatorContained(string str, List<string> splitters)
        {
            for (int i = 0; i < splitters.Count; i++)
            {
                if (str.Contains(splitters[i]))
                {
                    return splitters[i];
                }
            }
            return "";
        }
        string CharSeparatorContained(string str, List<char> splitters)
        {
            char[] CharArray = str.ToCharArray();
            for (int i = 0; i < str.Length; i++)
            {
                if (CharContains(splitters, CharArray[i]))
                {
                    return CharArray[i].ToString();
                }
            }
            return "";
        }
        List<string> MyStringSplit(string str, List<string> separators) // for string separators like "&&" or "++"
        {
            List<string> ReturnedCharSeparatedTokens;//for ({x}{+}{2}) {&&} ({d}{-}{0})
            SplittedLine = new List<string>();
            while (IndexStringContains(str, separators) != -1)
            {
                int SeparatorIndex = IndexStringContains(str, separators);
                ReturnedCharSeparatedTokens = MyCharSplit(str.Substring(0, SeparatorIndex), m_Char_Delimeters);
                FillListOfStringWithStringArray(SplittedLine, ReturnedCharSeparatedTokens);
                //SplittedLine.Add(StringSeparatorContained(str, separators));
                SplittedLine.Add(str.Substring(SeparatorIndex, 2));
                str = str.Substring(SeparatorIndex + 2, str.Length - SeparatorIndex - 2);
            }
            ReturnedCharSeparatedTokens = MyCharSplit(str, m_Char_Delimeters);
            FillListOfStringWithStringArray(SplittedLine, ReturnedCharSeparatedTokens);
            return SplittedLine;
        }
        void CheckForSpacesAndAdd(List<string> StringList, string str)
        {
            char[] SpaceDelimeter = new char[1] { ' ' };
            string[] AfterSpaceSplitting = str.Split(SpaceDelimeter, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < AfterSpaceSplitting.Length; i++)
                StringList.Add(AfterSpaceSplitting[i]);
        }
        void FillListOfStringWithStringArray(List<string> StringList, List<string> StringArray)
        {
            char[] SpaceDelimeter = new char[1] { ' ' };
            string[] AfterSpaceSplitting = new string[2];
            for (int i = 0; i < StringArray.Count; i++)
            {
                AfterSpaceSplitting = StringArray[i].Split(SpaceDelimeter, StringSplitOptions.RemoveEmptyEntries);
                try // 3ashan law aslan el token zat nafso space..
                {
                    StringList.Add(AfterSpaceSplitting[0]);
                }
                catch
                {
                    // DO nothing :/
                }
            }
        }
        List<string> MyCharSplit(string str, List<char> separators) // for single char separators
        {
            CharSplittedTokens = new List<string>();
            while (IndexCharContains(str, separators) != -1)
            {
                int SeparatorIndex = IndexCharContains(str, separators);
                CheckForSpacesAndAdd(CharSplittedTokens, str.Substring(0, SeparatorIndex));
                CharSplittedTokens.Add(CharSeparatorContained(str, separators));
                if (SeparatorIndex < str.Length - 1)
                {
                    str = str.Substring(SeparatorIndex + 1, str.Length - SeparatorIndex - 1);
                }
                else
                {
                    str = "";
                    break;
                }
            }
            if (str != "")
                CharSplittedTokens.Add(str);
            return CharSplittedTokens;
        }
        void DetectDataBlock(string Line, int index)
        {
            m_Tokens = MyStringSplit(Line, m_String_Delimeters);
            CurrentScope = 1;
            CurrentToken = new Token(m_Tokens[0], 0);
            /// 1) ha3mel declaration node ta7t node "Data"

            TreeNode declaration = new TreeNode("Declaration_Statement");
            TreeNode TheDeclarationStatementFirstItem = new TreeNode(CurrentToken.tokenType);

            //TreeNode TheFirstToken = TheFirstToken.Nodes.Add(CurrentToken.tokenType);
            TreeNode TheFirstToken = TheDeclarationStatementFirstItem.Nodes.Add(CurrentToken.tokenType);
            declaration.Nodes.Add(TheFirstToken);
            root2.Nodes.Add(declaration);
            /// 2) el token type of the first token of the statement yet3emel ta7t "Declaration_Statement"
            TheFirstToken.Nodes.Add(CurrentToken.name);
            /// 3) w ba3deeha el token name..
            string TypeOfStatement = "Declaration_Statement";
            ExpectNextTokens(m_Tokens, CurrentToken, declaration, TypeOfStatement);
            /// 4) w ba3den anady 3ala "Expect()" w adelha ba2et el tokens
        }
        void DetectStatement(string Line, int index)
        {
            //char[] m_Delimeters = new char[22] { "&&", "||", "++", "--", "<=", ">=", "!=", "==", "+", "-", "*", "/", "%", "=", "<", ">", ";", "(", ")", "[", "]", ";" };
            string TypeOfStatement;
            //m_Tokens = Line.Split(' ');
            m_Tokens = MyStringSplit(Line, m_String_Delimeters);
            //int asd = 0;
            if (m_Tokens[0] == "{")
            {
                m_CurrentScopeNewIntegerCounter[CurrentScope] = 0;
                m_CurrentScopeNewCharacterCounter[CurrentScope] = 0;
                m_CurrentScopeNewIntegerArrayCounter[CurrentScope] = 0;
                m_CurrentScopeNewCharacterArrayCounter[CurrentScope] = 0;
                m_CurrentScopeNewHashtableCounter[CurrentScope] = 0;
                CurrentScope++;

                CurrentBlockNodeIndex++;
                if (CurrentBlockNodeIndex == 2) // for the atomic part
                {
                    CurrentBlockNode[CurrentBlockNodeIndex] = new TreeNode("Sequence_Of_Statements");
                    CurrentBlockNode[CurrentBlockNodeIndex - 1].Nodes.Add(CurrentBlockNode[CurrentBlockNodeIndex]);
                }
                //else if (CurrentToken.name == "else") // for the ELSE part
                //{
                //    CurrentBlockNode[CurrentBlockNodeIndex] = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add("Sequence_Of_Statements");
                //}
                else // for the other blocks
                {
                    CurrentBlockNode[CurrentBlockNodeIndex] = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add("Sequence_Of_Statements");
                }
                m_CurledBrackets.Push((object)m_Tokens[0]);
                CurrentNode = CurrentBlockNode[CurrentBlockNodeIndex];

                TypeOfStatement = CurrentToken.statementType;
            }
            else if (m_Tokens[0] == "}")
            {
                CurrentBlockNodeIndex--;
                m_CurledBrackets.Pop();
                if (CurrentBlockNodeIndex == 1)
                    CurrentNode = CurrentBlockNode[CurrentBlockNodeIndex - 1];
                else
                    CurrentNode = CurrentBlockNode[CurrentBlockNodeIndex];

                TypeOfStatement = CurrentToken.statementType;
                
                for (int i = 0; i < m_CurrentScopeNewCharacterCounter[CurrentScope]; i++)
                    m_DeclaredCharacters.Pop();
                for (int i = 0; i < m_CurrentScopeNewIntegerCounter[CurrentScope]; i++)
                    m_DeclaredIntegers.Pop();
                for (int i = 0; i < m_CurrentScopeNewIntegerArrayCounter[CurrentScope]; i++)
                    m_DeclaredIntegersArray.Pop();
                for (int i = 0; i < m_CurrentScopeNewCharacterArrayCounter[CurrentScope]; i++)
                    m_DeclaredCharacterArray.Pop();
                for (int i = 0; i < m_CurrentScopeNewHashtableCounter[CurrentScope]; i++)
                    m_DeclaredHashtables.Pop();
                m_CurrentScopeNewCharacterCounter[CurrentScope] = 0;
                m_CurrentScopeNewIntegerCounter[CurrentScope] = 0;
                m_CurrentScopeNewCharacterArrayCounter[CurrentScope] = 0;
                m_CurrentScopeNewIntegerArrayCounter[CurrentScope] = 0;
                m_CurrentScopeNewHashtableCounter[CurrentScope] = 0;
                CurrentScope--;
            }
            else
            {
                CurrentToken = new Token(m_Tokens[0], 0);
                if (CurrentBlockNodeIndex == 1)
                {
                    if (CurrentToken.name == "else")
                    {
                        statementNode = CurrentBlockNode[CurrentBlockNodeIndex + 1].Parent; // hayedrab law mafeesh "if"
                        string ElseTokenType = "Reserved_Word";
                        tokenNode = statementNode.Nodes.Add(ElseTokenType);
                        CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                        CurrentNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        //have to handle that there's only ONE else after THE "if" !!
                    }
                    else
                    {
                        //statementNode = CurrentNode.Nodes.Add(CurrentToken.StatementType);
                        if (IfStackContains(m_DeclaredIntegersArray, CurrentToken.name) || IfStackContains(m_DeclaredIntegers, CurrentToken.name) || IfStackContains(m_DeclaredHashtables, CurrentToken.name) || IfStackContains(m_DeclaredCharacters, CurrentToken.name) || IfStackContains(m_DeclaredCharacterArray, CurrentToken.name) || StringSeparatorContained(CurrentToken.name, m_DoubleExpressionOperatorsBorA) != "")
                            CurrentToken.statementType = "Assignment_Statement";
                        statementNode = CurrentBlockNode[CurrentBlockNodeIndex - 1].Nodes.Add(CurrentToken.statementType);
                        tokenNode = statementNode.Nodes.Add(CurrentToken.tokenType);
                        CurrentBlockNode[CurrentBlockNodeIndex] = statementNode;
                        if (statementNode.Text == "Atomic_Block")
                            CurrentNode = CurrentBlockNode[CurrentBlockNodeIndex - 1];
                        else
                            CurrentNode = CurrentBlockNode[CurrentBlockNodeIndex];
                    }
                }
                else if (CurrentToken.name == "else")
                {
                    statementNode = CurrentBlockNode[CurrentBlockNodeIndex + 1].Parent; // hayedrab law mafeesh "if"
                    string ElseTokenType = "Reserved_Word";
                    tokenNode = statementNode.Nodes.Add(ElseTokenType);
                    CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                    CurrentNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    //have to handle that there's only ONE else after THE "if" !!
                }
                else
                {
                    if (IfStackContains(m_DeclaredIntegersArray, CurrentToken.name) || IfStackContains(m_DeclaredIntegers, CurrentToken.name) || IfStackContains(m_DeclaredHashtables, CurrentToken.name) || IfStackContains(m_DeclaredCharacters, CurrentToken.name) || IfStackContains(m_DeclaredCharacterArray, CurrentToken.name) || StringSeparatorContained(CurrentToken.name, m_DoubleExpressionOperatorsBorA) != "")
                        CurrentToken.statementType = "Assignment_Statement";
                    statementNode = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add(CurrentToken.statementType);
                    tokenNode = statementNode.Nodes.Add(CurrentToken.tokenType);
                    CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                    CurrentNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                }
                TypeOfStatement = CurrentToken.statementType;
                tokenNode.Nodes.Add(CurrentToken.name);
                m_TypeOfStatement[index] = CurrentToken.statementType;
                if (m_Tokens.Count > 1)
                {
                    TypeOfStatement = CurrentToken.statementType;
                    CurrentToken = new Token(m_Tokens[1], 1);
                    //CurrentToken.StatementType = m_TypeOfStatement[index];
                    CurrentToken.statementType = TypeOfStatement;
                    //CurrentToken.StatementType = "Declaration_Statement";
                }
                ExpectNextTokens(m_Tokens, CurrentToken, CurrentNode, TypeOfStatement);
            }
        }
        void ExpectNextTokens(List<string> TheTokens, Token CurrToken, TreeNode CurrNode, string TypeOfStatement)
        {
            string[] SemiColonSeparator = new string[1];
            //TreeNode ThisTempNode;
            //Token ThisToken;
            int index = 1;
            if (TypeOfStatement == "Declaration_Statement")
            {
                ResolveDeclarationStatement(0, TheTokens.Count - 1, index, TheTokens, CurrToken, CurrNode);
            }

            else if ((TypeOfStatement == "If_Statement" && TheTokens[0] != "else") || (TypeOfStatement == "While_Statement" && (TheTokens[0] != "t_while_n" && TheTokens[0] != "t_while_n_unordered")))
            {
                if (TheTokens[index] == "(") // hayedrab law mafeesh condition
                {
                    //DrawTokensOnTree("(", index, CurrToken, CurrNode);
                    index++;
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                    if (CurrentBlockNodeIndex == 1)
                    {
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                        ResolveCondition(2, TheTokens.Count - 2, index, TheTokens, CurrToken, CurrNode);
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                    }
                    else
                    {
                        //string ConditionStatement = "Condition";
                        //statementNode = CurrentBlockNode[CurrentBlockNodeIndex + 1].Nodes.Add(ConditionStatement);
                        //statementNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        ResolveCondition(2, TheTokens.Count - 2, index, TheTokens, CurrToken, CurrNode);
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    }
                    //////------------------------------------------------------------------------------------
                    //DrawTokensOnTree(TheTokens[2], 2, CurrToken, CurrNode);// 3ahsan "int"
                    //ResolveCondition(2, TheTokens.Count - 2, index, TheTokens, CurrToken, CurrNode);
                    ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++


                    if (TheTokens[TheTokens.Count - 1] == ")")
                    {
                        //DrawTokensOnTree(")", TheTokens.Count - 1, CurrToken, CurrNode); 
                    } //else ERROR

                } // else ERROR
            }
            else if (TypeOfStatement == "While_Statement" && (TheTokens[0] == "t_while_n" || TheTokens[0] == "t_while_n_unordered"))
            {
                if (TheTokens[index] == "(")
                {
                    //DrawTokensOnTree("(", index, CurrToken, CurrNode);
                    index++;
                    int StartingIndex = index;
                    int EndingIndex = index;
                    while (TheTokens[index] != ";")
                    {
                        EndingIndex++;
                        index++;
                    }

                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                    if (CurrentBlockNodeIndex == 1)
                    {
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                        ResolveCondition(StartingIndex, EndingIndex, StartingIndex + 1, TheTokens, CurrToken, CurrNode);
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                    }
                    else
                    {
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        ResolveCondition(StartingIndex, EndingIndex, StartingIndex + 1, TheTokens, CurrToken, CurrNode);
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    }
                    //string ConditionStatement = "Condition";
                    //statementNode = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add(ConditionStatement);
                    //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    //////------------------------------------------------------------------------------------
                    //ResolveCondition(StartingIndex, EndingIndex, StartingIndex + 1, TheTokens, CurrToken, CurrNode);
                    ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++

                    DrawTokensOnTree(";", index, CurrToken, CurrNode);
                    index++;
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                    if (CurrentBlockNodeIndex == 1)
                    {
                        string ExpressionStatement = "Expression";
                        TreeNode ExpNode1 = new TreeNode(ExpressionStatement);
                        //ResolveExpression(index, EndingIndex, index, TheTokens, CurrToken, ExpNode1);
                        //CurrNode.Nodes.Add(ExpNode1);
                        //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                        ResolveExpression(index, TheTokens.Count - 2, index, TheTokens, CurrToken, ExpNode1);
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                        CurrNode.Nodes.Add(ExpNode1);
                    }
                    else
                    {
                        string ExpressionStatement = "Expression";
                        TreeNode ExpNode1 = new TreeNode(ExpressionStatement);
                        ResolveExpression(index, TheTokens.Count - 2, index, TheTokens, CurrToken, ExpNode1);
                        CurrNode.Nodes.Add(ExpNode1);
                        //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        //ResolveExpression(index, TheTokens.Count - 2, index, TheTokens, CurrToken, CurrNode);
                        ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    }
                    //string ExpressionStatement = "Expression";
                    //statementNode = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add(ExpressionStatement);
                    //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    //////------------------------------------------------------------------------------------
                    //ResolveExpression(index, TheTokens.Count - 2, index, TheTokens, CurrToken, CurrNode);
                    ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++

                    if (TheTokens[TheTokens.Count - 1] == ")")
                    {
                        //DrawTokensOnTree(")", TheTokens.Count - 1, CurrToken, CurrNode);
                    }//else ERROR

                } // else ERROR
            }
            else if (TypeOfStatement == "For_Statement" && (TheTokens[0] != "t_for_n" && TheTokens[0] != "t_for_n_unordered"))
            {
                if (TheTokens[index] == "(")
                {
                    //DrawTokensOnTree("(", index, CurrToken, CurrNode);
                    index++;
                    int StartingIndex = index;
                    int EndingIndex = index;
                    //****might be some change if the ResolveAssignmentStatement will take the ";" with it or not
                    while (TheTokens[index] != ";")
                    {
                        EndingIndex++;
                        index++;
                        //must watch out cuz THERE might BE an ERROR.. causing this part to throw an excpetion
                        // ERROR -> missing ";"
                    }

                    if (TheTokens[StartingIndex] == "int" || TheTokens[StartingIndex] == "char" || TheTokens[StartingIndex] == "Hashtable")
                    {

                        if (CurrentBlockNodeIndex == 1)
                        {
                            TreeNode DecSt1 = new TreeNode("DeclarationStatement");
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];

                            ResolveDeclarationStatement(StartingIndex, EndingIndex, StartingIndex + 1, TheTokens, CurrToken, DecSt1);
                            CurrNode.Nodes.Add(DecSt1);
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                        }
                        else
                        {
                            TreeNode DecSt2 = new TreeNode("DeclarationStatement");
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];

                            ResolveDeclarationStatement(StartingIndex, EndingIndex, StartingIndex + 1, TheTokens, CurrToken, DecSt2);
                            CurrNode.Nodes.Add(DecSt2);
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        }
                    }
                    else if (IfStackContains(m_DeclaredIntegersArray, TheTokens[StartingIndex]) || IfStackContains(m_DeclaredIntegers, TheTokens[StartingIndex]) || IfStackContains(m_DeclaredHashtables, TheTokens[StartingIndex]) || IfStackContains(m_DeclaredCharacters, TheTokens[StartingIndex]) || IfStackContains(m_DeclaredCharacterArray, TheTokens[StartingIndex]))
                    {
                        if (CurrentBlockNodeIndex == 1)
                        {
                            TreeNode AsnSt1 = new TreeNode("AssignmentStatement");
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];

                            ResolveAssignmentStatement(StartingIndex, EndingIndex, StartingIndex, TheTokens, CurrToken, AsnSt1);
                            CurrNode.Nodes.Add(AsnSt1);
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                        }
                        else
                        {
                            TreeNode AsnSt2 = new TreeNode("AssignmentStatement");
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];

                            ResolveAssignmentStatement(StartingIndex, EndingIndex, StartingIndex, TheTokens, CurrToken, AsnSt2);
                            CurrNode.Nodes.Add(AsnSt2);
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        }
                    }
                    else
                    {
                        //ERROR
                    }
                    //will NEED to REMOVE used variable by the end of the forloop

                    //****until here probably...

                    DrawTokensOnTree(";", index, CurrToken, CurrNode);
                    index++;
                    StartingIndex = index;
                    EndingIndex = index;
                    while (TheTokens[index] != ";")
                    {
                        EndingIndex++;
                        index++;
                    }

                    //=====================================================
                    if (CurrentBlockNodeIndex == 1)
                    {
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                        ResolveCondition(StartingIndex, EndingIndex, StartingIndex + 1, TheTokens, CurrToken, CurrNode);
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                    }
                    else
                    {
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        ResolveCondition(StartingIndex, EndingIndex, StartingIndex + 1, TheTokens, CurrToken, CurrNode);
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    }

                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                    //string ConditionStatement = "Condition";
                    //statementNode = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add(ConditionStatement);
                    //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    ////////------------------------------------------------------------------------------------
                    ////DrawTokensOnTree(TheTokens[StartingIndex], StartingIndex, CurrToken, CurrNode);// 3ahsan "int"
                    //ResolveCondition(StartingIndex, EndingIndex, StartingIndex + 1, TheTokens, CurrToken, CurrNode);
                    ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    DrawTokensOnTree(";", index, CurrToken, CurrNode);
                    index++;

                    //=====================================================
                    if (CurrentBlockNodeIndex == 1)
                    {
                        TreeNode AsnSt1 = new TreeNode("AssignmentStatement");
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];

                        ResolveAssignmentStatement(index, TheTokens.Count - 2, index, TheTokens, CurrToken, AsnSt1);
                        CurrNode.Nodes.Add(AsnSt1);
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                    }
                    else
                    {
                        TreeNode AsnSt2 = new TreeNode("AssignmentStatement");
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];

                        ResolveAssignmentStatement(index, TheTokens.Count - 2, index, TheTokens, CurrToken, AsnSt2);
                        CurrNode.Nodes.Add(AsnSt2);
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    }
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                    //string AssignmentStatement2 = "Assignment_Statement";
                    //statementNode = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add(AssignmentStatement2);
                    //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    ////////------------------------------------------------------------------------------------
                    ////DrawTokensOnTree(TheTokens[StartingIndex], StartingIndex, CurrToken, CurrNode);// 3ahsan "int"
                    //ResolveAssignmentStatement(index, TheTokens.Count - 2, index, TheTokens, CurrToken, CurrNode);
                    ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++

                    if (TheTokens[TheTokens.Count - 1] == ")")
                    {
                        //DrawTokensOnTree(")", TheTokens.Count - 1, CurrToken, CurrNode);
                    }//else ERROR

                } // else ERROR
            }
            else if (TypeOfStatement == "For_Statement" && (TheTokens[0] == "t_for_n" || TheTokens[0] == "t_for_n_unordered"))
            {
                if (TheTokens[index] == "(")
                {
                    //DrawTokensOnTree("(", index, CurrToken, CurrNode);
                    index++;
                    int StartingIndex = index;
                    int EndingIndex = index;
                    //might be some change if the ResolveAssignmentStatement will take the ";" with it or not
                    while (TheTokens[index] != ";")
                    {
                        EndingIndex++;
                        index++;
                    }
                    if (TheTokens[StartingIndex] == "int" || TheTokens[StartingIndex] == "char" || TheTokens[StartingIndex] == "Hashtable")
                    {
                        if (CurrentBlockNodeIndex == 1)
                        {
                            TreeNode DecSt1 = new TreeNode("DeclarationStatement");
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];

                            ResolveDeclarationStatement(StartingIndex, EndingIndex, StartingIndex + 1, TheTokens, CurrToken, DecSt1);
                            CurrNode.Nodes.Add(DecSt1);
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                        }
                        else
                        {
                            TreeNode DecSt2 = new TreeNode("DeclarationStatement");
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];

                            ResolveDeclarationStatement(StartingIndex, EndingIndex, StartingIndex + 1, TheTokens, CurrToken, DecSt2);
                            CurrNode.Nodes.Add(DecSt2);
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        }
                        //////// 3ashan teb2a "int i = 0" ta7t Assignment_Statement, msh ta7t el For 3ala tool
                        //string DeclarationStatement = "Declaration_Statement";
                        //statementNode = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add(DeclarationStatement);
                        //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                        //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        ////////------------------------------------------------------------------------------------
                        //DrawTokensOnTree(TheTokens[StartingIndex], StartingIndex, CurrToken, CurrNode);// 3ahsan "int"
                        //ResolveDeclarationStatement(StartingIndex, EndingIndex, StartingIndex + 1, TheTokens, CurrToken, CurrNode);
                        //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                    }
                    else if (IfStackContains(m_DeclaredIntegersArray, TheTokens[StartingIndex]) || IfStackContains(m_DeclaredIntegers, TheTokens[StartingIndex]) || IfStackContains(m_DeclaredHashtables, TheTokens[StartingIndex]) || IfStackContains(m_DeclaredCharacters, TheTokens[StartingIndex]) || IfStackContains(m_DeclaredCharacterArray, TheTokens[StartingIndex]))
                    {
                        if (CurrentBlockNodeIndex == 1)
                        {
                            TreeNode AsnSt1 = new TreeNode("AssignmentStatement");
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];

                            ResolveAssignmentStatement(StartingIndex, EndingIndex, StartingIndex + 1, TheTokens, CurrToken, AsnSt1);
                            CurrNode.Nodes.Add(AsnSt1);
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                        }
                        else
                        {
                            TreeNode AsnSt2 = new TreeNode("AssignmentStatement");
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];

                            ResolveAssignmentStatement(StartingIndex, EndingIndex, StartingIndex + 1, TheTokens, CurrToken, AsnSt2);
                            CurrNode.Nodes.Add(AsnSt2);
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        }
                        //if (CurrentBlockNodeIndex == 1)
                        //{
                        //    CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                        //    ResolveAssignmentStatement(StartingIndex, EndingIndex, StartingIndex + 1, TheTokens, CurrToken, CurrNode);
                        //    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        //    CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                        //}
                        //else
                        //{
                        //    CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        //    ResolveAssignmentStatement(StartingIndex, EndingIndex, StartingIndex + 1, TheTokens, CurrToken, CurrNode);
                        //    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        //    CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        //}
                        //string AssignmentStatement = "Assignment_Statement";
                        //statementNode = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add(AssignmentStatement);
                        //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                        //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        ////////------------------------------------------------------------------------------------
                        //DrawTokensOnTree(TheTokens[StartingIndex], StartingIndex, CurrToken, CurrNode);// 3ahsan "int"
                        //ResolveAssignmentStatement(StartingIndex, EndingIndex, StartingIndex + 1, TheTokens, CurrToken, CurrNode);
                        //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                    }
                    else
                    {
                        //ERROR
                    }
                    //will need to remove used variable by the end of the forloop
                    //DrawTokensOnTree(";", index, CurrToken, CurrNode);
                    //until here probably...
                    DrawTokensOnTree(";", index, CurrToken, CurrNode);
                    index++;
                    StartingIndex = index;
                    EndingIndex = index;
                    while (TheTokens[index] != ";")
                    {
                        EndingIndex++;
                        index++;
                    }

                    //=====================================================

                    if (CurrentBlockNodeIndex == 1)
                    {
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                        ResolveCondition(StartingIndex, EndingIndex, StartingIndex, TheTokens, CurrToken, CurrNode);
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                    }
                    else
                    {
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        ResolveCondition(StartingIndex, EndingIndex, StartingIndex, TheTokens, CurrToken, CurrNode);
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    }
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                    //string ConditionStatement = "Condition";
                    //statementNode = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add(ConditionStatement);
                    //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    ////////------------------------------------------------------------------------------------
                    ////DrawTokensOnTree(TheTokens[StartingIndex], StartingIndex, CurrToken, CurrNode);// 3ahsan "int"
                    //ResolveCondition(StartingIndex, EndingIndex, StartingIndex, TheTokens, CurrToken, CurrNode);
                    ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++

                    DrawTokensOnTree(";", index, CurrToken, CurrNode);
                    index++;
                    StartingIndex = index;
                    EndingIndex = index;
                    while (TheTokens[index] != ";")
                    {
                        EndingIndex++;
                        index++;
                    }//TRY w CATCH 3ashan ERROR law: t_for_n(int i =0; i < 34; i ++)

                    //=====================================================
                    if (CurrentBlockNodeIndex == 1)
                    {
                        TreeNode AsnSt2 = new TreeNode("AssignmentStatement");
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];

                        ResolveAssignmentStatement(StartingIndex, EndingIndex, StartingIndex, TheTokens, CurrToken, AsnSt2);
                        CurrNode.Nodes.Add(AsnSt2);
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                    }
                    else
                    {
                        TreeNode AsnSt2 = new TreeNode("AssignmentStatement");
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];

                        ResolveAssignmentStatement(StartingIndex, EndingIndex, StartingIndex, TheTokens, CurrToken, AsnSt2);
                        CurrNode.Nodes.Add(AsnSt2);
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    }
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                    //string AssignmentStatement2 = "Assignment_Statement";
                    //statementNode = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add(AssignmentStatement2);
                    //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    ////////------------------------------------------------------------------------------------
                    ////DrawTokensOnTree(TheTokens[StartingIndex], StartingIndex, CurrToken, CurrNode);// 3ahsan "int"
                    //ResolveAssignmentStatement(StartingIndex, EndingIndex, StartingIndex, TheTokens, CurrToken, CurrNode);
                    ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++

                    DrawTokensOnTree(";", index, CurrToken, CurrNode);
                    index++;
                    //=====================================================

                    if (CurrentBlockNodeIndex == 1)
                    {
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                        ResolveExpression(index, TheTokens.Count - 2, index, TheTokens, CurrToken, CurrNode);
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex];
                    }
                    else
                    {
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        ResolveExpression(index, TheTokens.Count - 2, index, TheTokens, CurrToken, CurrNode);
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    }
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                    //string ExpressionStatement = "Expression";
                    //statementNode = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add(ExpressionStatement);
                    //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    ////////------------------------------------------------------------------------------------
                    ////DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);// 3ahsan "int"
                    //ResolveExpression(index, TheTokens.Count - 2, index, TheTokens, CurrToken, CurrNode);
                    ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++

                    if (TheTokens[TheTokens.Count - 1] == ")")
                    {
                        //DrawTokensOnTree(")", TheTokens.Count - 1, CurrToken, CurrNode);
                    }//else ERROR

                } // else ERROR
            }
            else if (TypeOfStatement == "Lock_Block") // MUST handle the OBJECT thing
            {
                if (TheTokens[1] == "(")
                {
                    //DrawTokensOnTree("(", 1, CurrToken, CurrNode);
                    // the OBJECT
                    DrawTokensOnTree(TheTokens[2], 2, CurrToken, CurrNode);
                    // LOCALITY
                    //  SHOULD ask about EXACT syntax
                    if (TheTokens[TheTokens.Count - 1] == ")")
                    {
                        //DrawTokensOnTree(")", TheTokens.Count - 1, CurrToken, CurrNode);
                    }//else ERROR
                }
            }
            else if (TypeOfStatement == "Assignment_Statement")
            {
                ResolveAssignmentStatement(0, TheTokens.Count - 1, 0, TheTokens, CurrToken, CurrNode);
            }
        }
        bool IfStackContains(Stack st, string str)
        {
            foreach (object obj in st)
            {
                string StackObject = obj.ToString();
                if (StackObject == str)
                    return true;
            }
            return false;
        }
        void ResolveAssignmentStatement(int StartingIndex, int EndingIndex, int index, List<string> TheTokens, Token CurrToken, TreeNode CurrNode)
        {
            //if (m_DeclaredIntegers.Contains(TheTokens[StartingIndex]))
            if (IfStackContains(m_DeclaredIntegers, TheTokens[StartingIndex]))
            {
                if (CurrentToken.statementType != "Assignment_Statement")
                    DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                index++;
                if (TheTokens[index] == "=" || StringSeparatorContained(TheTokens[index], m_DoubleExpressionOperatorsA) != "") // = OR += OR -= OR *= OR /=
                {
                    DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                    index++;

                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                    string ExpressionStatement = "Expression";
                    if (CurrToken.statementType == "For_Statement" || CurrentToken.statementType == "While_Statement")//|| CurrNode.Parent.Text == "Sequence_Of_Statements")
                    {
                        //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add(ExpressionStatement);
                        TreeNode ExpNode1 = new TreeNode(ExpressionStatement);
                        ResolveExpression(index, EndingIndex, index, TheTokens, CurrToken, ExpNode1);
                        CurrNode.Nodes.Add(ExpNode1);
                        //if (CurrNode.Parent.Parent.Text == "Sequence_Of_Statements" || CurrentToken.statementType == "If_Statement")
                        //    CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1]; // 3ashan aragga3 el 7agat ta7t elly abl el "SeqOfSt" tany
                    }
                    else
                    {
                        //statementNode = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add(ExpressionStatement);
                        //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                        //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        TreeNode ExpNode = new TreeNode(ExpressionStatement);
                        //////------------------------------------------------------------------------------------
                        //DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);// 3ahsan "int"
                        ResolveExpression(index, TheTokens.Count - 2, index, TheTokens, CurrToken, ExpNode);
                        CurrNode.Nodes.Add(ExpNode);
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        if(CurrentBlockNodeIndex == 1)
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t el "For" tany
                        else
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];

                    }
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    if (TheTokens[EndingIndex] == ";" && (CurrToken.statementType != "For_Statement" && CurrToken.statementType != "While_Statement"))
                        DrawTokensOnTree(TheTokens[EndingIndex], EndingIndex, CurrToken, CurrNode);
                }
                else if (StringSeparatorContained(TheTokens[index], m_DoubleExpressionOperatorsBorA) != "") // ++ OR --
                {
                    DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                    index++;
                    ////+++++++++++++++++++++++++++++++++++++++++++++++++++++
                    // kan fe zay elly foo2.. :)
                    ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    if (TheTokens[EndingIndex] == ";" && (CurrToken.statementType != "For_Statement" && CurrToken.statementType != "While_Statement"))// && CurrNode.Parent.Text != "Sequence_Of_Statements")
                        DrawTokensOnTree(TheTokens[EndingIndex], EndingIndex, CurrToken, CurrNode);
                }
            }
            else if (StringSeparatorContained(TheTokens[StartingIndex], m_DoubleExpressionOperatorsBorA) != "")//++i; integers and chars ONLY
            {
                //DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                index++;
                if (IfStackContains(m_DeclaredIntegers, TheTokens[index]) || IfStackContains(m_AssignedCharachters, TheTokens[index]))
                {
                    DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                    index++;
                }
                if (TheTokens[EndingIndex] == ";" && (CurrToken.statementType != "For_Statement" || CurrToken.statementType != "While_Statement"))
                    DrawTokensOnTree(TheTokens[EndingIndex], EndingIndex, CurrToken, CurrNode);
            }
            else if (IfStackContains(m_DeclaredCharacters, TheTokens[StartingIndex]))
            {
                if (CurrentToken.statementType != "Assignment_Statement")
                    DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                index++;
                if (TheTokens[index] == "=")
                {
                    DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                    index++;

                    if (TheTokens[index][0] == '\'' && TheTokens[index][2] == '\'' && TheTokens[index].Length == 3)
                    {
                        //string CharacterVar = TheTokens[index] + TheTokens[index + 1] + TheTokens[index + 2];
                        DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                        index++;
                        if (TheTokens[index] == ";" && EndingIndex == index && (CurrToken.statementType != "For_Statement" || CurrToken.statementType != "While_Statement"))// && CurrNode.Parent.Text != "Sequence_Of_Statements") // to ensure that there's nothing after the ";"
                            DrawTokensOnTree(TheTokens[EndingIndex], EndingIndex, CurrToken, CurrNode);
                    }
                    else if (IfStackContains(m_DeclaredCharacters, TheTokens[index]))
                    {
                        DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                        index++;
                        if (TheTokens[index] == ";" && EndingIndex == index && (CurrToken.statementType != "For_Statement" || CurrToken.statementType != "While_Statement"))// && CurrNode.Parent.Text != "Sequence_Of_Statements") // to ensure that there's nothing after the ";"
                            DrawTokensOnTree(TheTokens[EndingIndex], EndingIndex, CurrToken, CurrNode);
                    }
                    else if (IfStackContains(m_DeclaredCharacterArray, TheTokens[index]))
                    {
                        DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                        index++;
                        if (TheTokens[index] == "[" && TheTokens[EndingIndex - 1] == "]" && TheTokens[EndingIndex] == ";")
                        {
                            DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                            index++;
                            int StartingIndexInner = index;
                            int EndingIndexInner = index;
                            while (TheTokens[index] != "]")
                            {
                                EndingIndexInner++;
                                index++;
                            }
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                            string ExpressionStatement = "Expression";
                            TreeNode ExpNode4 = new TreeNode(ExpressionStatement);
                            ResolveExpression(StartingIndexInner, EndingIndexInner - 1, StartingIndexInner, TheTokens, CurrToken, ExpNode4);
                            CurrNode.Nodes.Add(ExpNode4);
                            if (TheTokens[index] == "]")
                            {
                                DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                                index++;
                                if (TheTokens[index] == ";" && EndingIndex == index && (CurrToken.statementType != "For_Statement" || CurrToken.statementType != "While_Statement"))// && CurrNode.Parent.Text != "Sequence_Of_Statements") // to ensure that there's nothing after the ";"
                                    DrawTokensOnTree(TheTokens[EndingIndex], EndingIndex, CurrToken, CurrNode); // ";"
                            }
                        }
                    }
                }
            }
            else if (IfStackContains(m_DeclaredIntegersArray, TheTokens[StartingIndex]))
            {
                index++;
                if (TheTokens[index] == "[")
                {
                    DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                    index++;
                    int StartingIndexInner = index;
                    int EndingIndexInner = index;
                    while (TheTokens[index] != "]")
                    {
                        EndingIndexInner++;
                        index++;
                    }
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                    string ExpressionStatement = "Expression";

                    if (CurrToken.statementType == "For_Statement" || CurrentToken.statementType == "If_Statement")//|| CurrNode.Parent.Parent.Text == "Sequence_Of_Statements")
                    {
                        CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1].Nodes.Add(ExpressionStatement);
                        ResolveExpression(index, TheTokens.Count - 2, index, TheTokens, CurrToken, CurrNode);
                        if (CurrNode.Parent.Parent.Text == "Sequence_Of_Statements")
                            CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1]; // 3ashan aragga3 el 7agat ta7t elly abl el "SeqOfSt" tany
                    }

                    TreeNode ExpNode1 = new TreeNode(ExpressionStatement);
                    ResolveExpression(StartingIndexInner, EndingIndexInner - 1, StartingIndexInner, TheTokens, CurrToken, ExpNode1);
                    CurrNode.Nodes.Add(ExpNode1);

                    //statementNode = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add(ExpressionStatement);
                    //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    ////////------------------------------------------------------------------------------------
                    ////DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);// 3ahsan "int"
                    //ResolveExpression(StartingIndexInner, EndingIndexInner-1, StartingIndexInner, TheTokens, CurrToken, CurrNode);
                    ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    //index++;
                    if (TheTokens[index] == "]")
                    {
                        DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                        index++;
                        if (TheTokens[index] == "=" || StringSeparatorContained(TheTokens[index], m_DoubleExpressionOperatorsA) != "")
                        {
                            DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                            index++;
                            StartingIndexInner = index;
                            EndingIndexInner = index;
                            while (TheTokens[index] != ";")
                            {
                                EndingIndexInner++;
                                index++;
                            }
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                            TreeNode ExpNode2 = new TreeNode(ExpressionStatement);
                            ResolveExpression(StartingIndexInner, EndingIndexInner - 1, StartingIndexInner, TheTokens, CurrToken, ExpNode2);
                            CurrNode.Nodes.Add(ExpNode2);
                            //ExpressionStatement = "Expression";
                            //statementNode = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add(ExpressionStatement);
                            //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                            //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                            ////////------------------------------------------------------------------------------------
                            ////DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                            //ResolveExpression(StartingIndexInner, EndingIndexInner, StartingIndexInner, TheTokens, CurrToken, CurrNode);
                            ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                            //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++

                            if (TheTokens[index] == ";" && EndingIndex == index && (CurrToken.statementType != "For_Statement" || CurrToken.statementType != "While_Statement"))// && CurrNode.Parent.Text != "Sequence_Of_Statements") // to ensure that there's nothing after the ";"
                                DrawTokensOnTree(TheTokens[EndingIndex], EndingIndex, CurrToken, CurrNode);
                        }
                    }
                }
                else if (TheTokens[index] == "=")
                {
                    DrawTokensOnTree(TheTokens[index], EndingIndex, CurrToken, CurrNode);
                    index++;
                    if (IfStackContains(m_DeclaredIntegersArray, TheTokens[index]) || IfStackContains(m_DeclaredCharacterArray, TheTokens[index]))
                    {
                        DrawTokensOnTree(TheTokens[index], EndingIndex, CurrToken, CurrNode);
                        index++;
                        //--------SHOULD know if the length will ALWAYS be 4------
                        if (TheTokens.Count == 4 && TheTokens[index] == ";" && CurrToken.statementType != "For_Statement")// && CurrNode.Parent.Text != "Sequence_Of_Statements") // to ensure that there's nothing after the ";"
                            DrawTokensOnTree(TheTokens[EndingIndex], EndingIndex, CurrToken, CurrNode);
                    }
                }
            }
            else if (IfStackContains(m_DeclaredCharacterArray, TheTokens[StartingIndex]))
            {
                index++;
                if (TheTokens[index] == "[")
                {
                    DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                    index++;
                    int StartingIndexInner = index;
                    int EndingIndexInner = index;
                    while (TheTokens[index] != "]")
                    {
                        EndingIndexInner++;
                        index++;
                    }
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                    string ExpressionStatement = "Expression";
                    TreeNode ExpNode3 = new TreeNode(ExpressionStatement);
                    ResolveExpression(StartingIndexInner, EndingIndexInner - 1, StartingIndexInner, TheTokens, CurrToken, ExpNode3);
                    CurrNode.Nodes.Add(ExpNode3);

                    //statementNode = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add(ExpressionStatement);
                    //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                    ////////------------------------------------------------------------------------------------
                    ////DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);// 3ahsan "int"
                    //ResolveExpression(StartingIndexInner, EndingIndexInner - 1, StartingIndexInner, TheTokens, CurrToken, CurrNode);
                    ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    //index++;
                    if (TheTokens[index] == "]")
                    {
                        DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                        index++;
                        if (TheTokens[index] == "=")
                        {
                            DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                            index++;
                            if (TheTokens[index][0] == '\'' && TheTokens[index][2] == '\'' && TheTokens[index].Length == 3)
                            {
                                //string CharacterVar = TheTokens[index] + TheTokens[index + 1] + TheTokens[index + 2];
                                DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                                index++;
                                if (TheTokens[index] == ";" && EndingIndex == index && (CurrToken.statementType != "For_Statement" || CurrToken.statementType != "While_Statement"))// && CurrNode.Parent.Text != "Sequence_Of_Statements") // to ensure that there's nothing after the ";"
                                    DrawTokensOnTree(TheTokens[EndingIndex], EndingIndex, CurrToken, CurrNode);
                            }
                            else if (IfStackContains(m_DeclaredCharacters, TheTokens[index]))
                            {
                                DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                                index++;
                                if (TheTokens[index] == ";" && EndingIndex == index && (CurrToken.statementType != "For_Statement" || CurrToken.statementType != "While_Statement"))// && CurrNode.Parent.Text != "Sequence_Of_Statements") // to ensure that there's nothing after the ";"
                                    DrawTokensOnTree(TheTokens[EndingIndex], EndingIndex, CurrToken, CurrNode);
                            }
                        }
                    }
                }
                else if (TheTokens[index] == "=")
                {
                    DrawTokensOnTree(TheTokens[index], EndingIndex, CurrToken, CurrNode);
                    index++;
                    if (IfStackContains(m_DeclaredCharacterArray, TheTokens[index]))
                    {
                        DrawTokensOnTree(TheTokens[index], EndingIndex, CurrToken, CurrNode);
                        index++;
                        //--------SHOULD know if the length will ALWAYS be 4------
                        if (TheTokens.Count == 4 && TheTokens[index] == ";" && (CurrToken.statementType != "For_Statement") || (CurrToken.statementType != "While_Statement"))// && CurrNode.Parent.Text != "Sequence_Of_Statements") // to ensure that there's nothing after the ";"
                            DrawTokensOnTree(TheTokens[EndingIndex], EndingIndex, CurrToken, CurrNode);

                    }
                }
            }
            else if (IfStackContains(m_DeclaredHashtables, TheTokens[StartingIndex]))
            {
                index++;
                if (TheTokens[index] == ".")
                {
                    index++;
                    if (TheTokens[index] == "add" || TheTokens[index] == "remove")
                    {
                        DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                        index++;
                        if (TheTokens[index] == "(" && TheTokens[EndingIndex - 1] == ")")
                        {
                            DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode); // "("
                            index++;
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                            string ExpressionStatement = "Expression";
                            TreeNode ExpNode11 = new TreeNode(ExpressionStatement);
                            ResolveExpression(index, TheTokens.Count - 2, index, TheTokens, CurrToken, ExpNode11);
                            CurrNode.Nodes.Add(ExpNode11);

                            //statementNode = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add(ExpressionStatement);
                            //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                            //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                            ////////------------------------------------------------------------------------------------
                            ////DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);// 3ahsan "int"
                            //ResolveExpression(index, TheTokens.Count - 2, index, TheTokens, CurrToken, CurrNode);
                            ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                            //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                            index++;
                            if (TheTokens[StartingIndex + 2] == "add" || TheTokens[index] == ",") //(exp,exp)
                            {
                                DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode); // ","
                                index++;

                                //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                                TreeNode ExpNode22 = new TreeNode(ExpressionStatement);
                                ResolveExpression(index, TheTokens.Count - 2, index, TheTokens, CurrToken, ExpNode22);
                                CurrNode.Nodes.Add(ExpNode22);
                                //ExpressionStatement = "Expression";
                                //statementNode = CurrentBlockNode[CurrentBlockNodeIndex].Nodes.Add(ExpressionStatement);
                                //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                                //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                                ////////------------------------------------------------------------------------------------
                                ////DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);// 3ahsan "int"
                                //ResolveExpression(index, TheTokens.Count - 2, index, TheTokens, CurrToken, CurrNode);
                                ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                                //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                                index++;
                            }
                            DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode); // ")"
                            index++;
                            if (TheTokens[index] == ";")
                                DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode); // ";"
                        }
                    }
                    else
                    {
                        //ERROR
                    }

                }
            }
        }
        void ResolveDeclarationStatement(int StartingIndex, int EndingIndex, int index, List<string> TheTokens, Token CurrToken, TreeNode CurrNode)
        {
            if (TheTokens[StartingIndex] == "int" || TheTokens[StartingIndex] == "char" || TheTokens[StartingIndex] == "Hashtable" || ((TheTokens[StartingIndex] == "int" || TheTokens[StartingIndex] == "char") && TheTokens[StartingIndex + 1] == "[" && TheTokens[StartingIndex + 2] == "]"))
            {
                if (CurrToken.statementType == "For_Statement")
                    DrawTokensOnTree(TheTokens[StartingIndex], index, CurrToken, CurrNode);
                if (TheTokens[index] == "[" && TheTokens[index + 1] == "]")
                {
                    DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                    index++;
                    DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                    index++;
                }
                if (m_Identifiers.IsMatch(TheTokens[index]) && !IfStackContains(m_DeclaredCharacterArray, TheTokens[index]) && !IfStackContains(m_DeclaredCharacters, TheTokens[index]) && !IfStackContains(m_DeclaredHashtables, TheTokens[index]) && !IfStackContains(m_DeclaredIntegers, TheTokens[index]) && !IfStackContains(m_DeclaredIntegersArray, TheTokens[index]))
                {
                    DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                    index++;
                    if (TheTokens[StartingIndex] == "int" && TheTokens[StartingIndex + 1] == "[" && TheTokens[StartingIndex + 2] == "]")
                    {
                        m_DeclaredIntegersArray.Push((object)TheTokens[StartingIndex + 3]);           // to be removed in the ERROR law fe
                        m_CurrentScopeNewIntegerArrayCounter[CurrentScope]++;
                        if (CurrentScope == 0 && CurrentBlockNode[CurrentBlockNodeIndex].Text == "Declaration_Statement")
                        {
                            lt = new LiteralTable();
                            lt.Name = TheTokens[StartingIndex + 3];
                            lt.Type = "int[]";
                            LiteralTableStack.Enqueue(lt);
                            LiteralTableDataName.Enqueue(lt.Name);
                            LiteralTableDataType.Enqueue(lt.Type);
                        }
                    }
                    else if (TheTokens[StartingIndex] == "char" && TheTokens[StartingIndex + 1] == "[" && TheTokens[StartingIndex + 2] == "]")
                    {
                        m_DeclaredCharacterArray.Push((object)TheTokens[StartingIndex + 3]);         // to be removed in the ERROR law fe
                        m_CurrentScopeNewCharacterArrayCounter[CurrentScope]++;
                        if (CurrentScope == 0 && CurrentBlockNode[CurrentBlockNodeIndex].Text == "Declaration_Statement")
                        {
                            lt = new LiteralTable();
                            lt.Name = TheTokens[StartingIndex + 3];
                            lt.Type = "char[]";
                            LiteralTableStack.Enqueue(lt);
                            LiteralTableDataName.Enqueue(lt.Name);
                            LiteralTableDataType.Enqueue(lt.Type);
                        }
                    }
                    else if (TheTokens[StartingIndex] == "Hashtable")
                    {
                        m_DeclaredHashtables.Push((object)TheTokens[StartingIndex + 1]);         // to be removed in the ERROR law fe
                        m_CurrentScopeNewHashtableCounter[CurrentScope]++;
                        if (CurrentScope == 0 && CurrentBlockNode[CurrentBlockNodeIndex].Text == "Declaration_Statement")
                        {
                            lt = new LiteralTable();
                            lt.Name = TheTokens[StartingIndex + 1];
                            lt.Type = "hashtable";
                            LiteralTableStack.Enqueue(lt);
                            LiteralTableDataName.Enqueue(lt.Name);
                            LiteralTableDataType.Enqueue(lt.Type);
                        }
                    }
                    else if (TheTokens[StartingIndex] == "int")
                    {
                        m_DeclaredIntegers.Push((object)TheTokens[StartingIndex + 1]);         // to be removed in the ERROR law fe
                        m_CurrentScopeNewIntegerCounter[CurrentScope]++;
                        if (CurrentScope == 0 && CurrentBlockNode[CurrentBlockNodeIndex].Text == "Declaration_Statement")
                        {
                            lt = new LiteralTable();
                            lt.Name = TheTokens[StartingIndex + 1];
                            lt.Type = "int";
                            LiteralTableStack.Enqueue(lt);
                            LiteralTableDataName.Enqueue(lt.Name);
                            LiteralTableDataType.Enqueue(lt.Type);
                        }
                    }
                    else if (TheTokens[StartingIndex] == "char")
                    {
                        m_DeclaredCharacters.Push((object)TheTokens[StartingIndex + 1]);         // to be removed in the ERROR law fe
                        m_CurrentScopeNewCharacterCounter[CurrentScope]++;
                        if (CurrentScope == 0 && CurrentBlockNode[CurrentBlockNodeIndex].Text == "Declaration_Statement")
                        {
                            lt = new LiteralTable();
                            lt.Name = TheTokens[StartingIndex + 1];
                            lt.Type = "char";
                            LiteralTableStack.Enqueue(lt);
                            LiteralTableDataName.Enqueue(lt.Name);
                            LiteralTableDataType.Enqueue(lt.Type);
                        }
                    }
                }
                // else ERROR (not a correct format OR declared before) 

                //This part could be removed upwards if the ERROR stops parsing of the rest of the SENTENCE
                if (TheTokens[index] == "=" && TheTokens[StartingIndex] == "int" && (TheTokens[StartingIndex + 1] != "[" && TheTokens[StartingIndex + 2] != "]"))
                {
                    DrawTokensOnTree("=", index, CurrToken, CurrNode);
                    index++;
                    int StartingExpressionIndex = index;
                    int EndingExpressionIndex = EndingIndex;
                    if (TheTokens[EndingExpressionIndex] == ";")
                    {

                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                        string ExpressionStatement = "Expression";
                        //statementNode = CurrentBlockNode[CurrentBlockNodeIndex ].Nodes.Add(ExpressionStatement);
                        //statementNode = CurrNode.Nodes.Add(ExpressionStatement);
                        //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                        //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                        TreeNode ExpNode = new TreeNode(ExpressionStatement);
                        //////------------------------------------------------------------------------------------
                        //DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);// 3ahsan "int"
                        ResolveExpression(StartingExpressionIndex, EndingExpressionIndex - 1, index, TheTokens, CurrToken, ExpNode);
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        CurrNode.Nodes.Add(ExpNode);
                        if (CurrToken.statementType != "For_Statement")
                            DrawTokensOnTree(";", index, CurrToken, CurrNode);
                    }

                    ////////////// law fe assignment fel declaration 
                    ////////////// (OR ERROR) - > else
                }
                else if (TheTokens[index] == "=" && TheTokens[StartingIndex] == "char" && (TheTokens[StartingIndex + 1] != "[" && TheTokens[StartingIndex + 2] != "]"))
                {

                    DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                    index++;

                    if (TheTokens[index][0] == '\'' && TheTokens[index][2] == '\'' && TheTokens[index].Length == 3)
                    {
                        //string CharacterVar = TheTokens[index] + TheTokens[index + 1] + TheTokens[index + 2];
                        DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                        index++;
                        if (TheTokens[index] == ";" && TheTokens.Count == index + 1) // to ensure that there's nothing after the ";"
                            DrawTokensOnTree(TheTokens[index], EndingIndex, CurrToken, CurrNode);
                    }
                    else if (IfStackContains(m_DeclaredCharacters, TheTokens[index]))
                    {
                        DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                        index++;
                        if (TheTokens[index] == ";" && TheTokens.Count == index + 1)
                            DrawTokensOnTree(TheTokens[index], EndingIndex, CurrToken, CurrNode);
                    }
                    else if (IfStackContains(m_DeclaredCharacterArray, TheTokens[index]))
                    {
                        DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                        index++;
                        if (TheTokens[index] == "[" && TheTokens[EndingIndex - 1] == "]" && TheTokens[EndingIndex] == ";")
                        {
                            DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                            index++;
                            int StartingIndexInner = index;
                            int EndingIndexInner = index;
                            while (TheTokens[index] != "]")
                            {
                                EndingIndexInner++;
                                index++;
                            }
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                            string ExpressionStatement = "Expression";
                            TreeNode ExpNode4 = new TreeNode(ExpressionStatement);
                            ResolveExpression(StartingIndexInner, EndingIndexInner - 1, StartingIndexInner, TheTokens, CurrToken, ExpNode4);
                            CurrNode.Nodes.Add(ExpNode4);
                            if (TheTokens[index] == "]")
                            {
                                DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                                index++;
                                if (TheTokens[index] == ";" && EndingIndex == index && (CurrToken.statementType != "For_Statement" || CurrToken.statementType != "While_Statement"))// && CurrNode.Parent.Text != "Sequence_Of_Statements") // to ensure that there's nothing after the ";"
                                    DrawTokensOnTree(TheTokens[EndingIndex], EndingIndex, CurrToken, CurrNode); // ";"
                            }
                        }
                    }
                }

                else if (TheTokens[index] == "=" && TheTokens[StartingIndex] == "Hashtable")
                {
                    DrawTokensOnTree("=", index, CurrToken, CurrNode);
                    index++;
                    if (TheTokens[index] == "new")
                    {
                        DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                        index++;
                        if (TheTokens[index] == TheTokens[StartingIndex] && TheTokens[index + 1] == "(" && TheTokens[EndingIndex - 1] == ")" && TheTokens[EndingIndex] == ";")
                        {
                            DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                            index++;
                            DrawTokensOnTree("(", index, CurrToken, CurrNode);
                            index++;
                            int StartingExpressionIndex = index;
                            int EndingExpressionIndex = EndingIndex - 2;

                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                            string ExpressionStatement = "Expression";
                            TreeNode ExpNode2 = new TreeNode(ExpressionStatement);
                            ResolveExpression(StartingExpressionIndex, EndingExpressionIndex, index, TheTokens, CurrToken, ExpNode2);
                            CurrNode.Nodes.Add(ExpNode2);
                            //statementNode = CurrentBlockNode[CurrentBlockNodeIndex ].Nodes.Add(ExpressionStatement);
                            //statementNode = CurrNode.Nodes.Add(ExpressionStatement);
                            //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                            //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                            ////////------------------------------------------------------------------------------------
                            ////DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);// 3ahsan "int"
                            //ResolveExpression(StartingExpressionIndex, EndingExpressionIndex, index, TheTokens, CurrToken, CurrNode);
                            ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                            //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++


                            index++;
                            DrawTokensOnTree(")", index, CurrToken, CurrNode);
                            index++;
                            if (CurrToken.statementType != "For_Statement")
                                DrawTokensOnTree(";", index, CurrToken, CurrNode);
                        }

                    }
                    else
                    {
                        //3'aleban Syntax ERROR
                    }
                }
                else if (TheTokens[index] == "=" && (TheTokens[StartingIndex] == "int" || TheTokens[StartingIndex] == "char") && TheTokens[StartingIndex + 1] == "[" && TheTokens[StartingIndex + 2] == "]")
                {
                    DrawTokensOnTree("=", index, CurrToken, CurrNode);
                    index++;
                    if (TheTokens[index] == "new")
                    {
                        DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                        index++;
                        if (TheTokens[index] == TheTokens[StartingIndex] && TheTokens[index + 1] == "[" && TheTokens[EndingIndex - 1] == "]" && TheTokens[EndingIndex] == ";")
                        {
                            DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);
                            index++;
                            DrawTokensOnTree("[", index, CurrToken, CurrNode);
                            index++;
                            int StartingExpressionIndex = index;
                            int EndingExpressionIndex = EndingIndex - 2;

                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++
                            string ExpressionStatement = "Expression";
                            TreeNode ExpNode3 = new TreeNode(ExpressionStatement);
                            ResolveExpression(StartingExpressionIndex, EndingExpressionIndex, index, TheTokens, CurrToken, ExpNode3);
                            CurrNode.Nodes.Add(ExpNode3);
                            //statementNode = CurrentBlockNode[CurrentBlockNodeIndex ].Nodes.Add(ExpressionStatement);
                            //statementNode = CurrNode.Nodes.Add(ExpressionStatement);
                            //CurrentBlockNode[CurrentBlockNodeIndex + 1] = statementNode;
                            //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex + 1];
                            ////////------------------------------------------------------------------------------------
                            ////DrawTokensOnTree(TheTokens[index], index, CurrToken, CurrNode);// 3ahsan "int"
                            //ResolveExpression(StartingExpressionIndex, EndingExpressionIndex, index, TheTokens, CurrToken, CurrNode);
                            ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                            //CurrNode = CurrentBlockNode[CurrentBlockNodeIndex]; // 3ashan aragga3 el 7agat ta7t le "For" tany
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++


                            index++;
                            DrawTokensOnTree("]", index, CurrToken, CurrNode);
                            index++;
                            if (CurrToken.statementType != "For_Statement")
                                DrawTokensOnTree(";", index, CurrToken, CurrNode);
                        }

                    }
                    else if (TheTokens[StartingIndex] == "int" && (IfStackContains(m_DeclaredIntegersArray, TheTokens[index]) || IfStackContains(m_DeclaredCharacterArray, TheTokens[index])))
                    {
                        DrawTokensOnTree(TheTokens[index], EndingIndex, CurrToken, CurrNode);
                        index++;
                        //--------SHOULD know if the length will ALWAYS be 4------
                        if (TheTokens.Count == 7 && TheTokens[index] == ";" && CurrToken.statementType != "For_Statement")// && CurrNode.Parent.Text != "Sequence_Of_Statements") // to ensure that there's nothing after the ";"
                            DrawTokensOnTree(TheTokens[EndingIndex], EndingIndex, CurrToken, CurrNode);
                    }
                    else if (TheTokens[StartingIndex] == "char" && IfStackContains(m_DeclaredCharacterArray, TheTokens[index]))
                    {
                        DrawTokensOnTree(TheTokens[index], EndingIndex, CurrToken, CurrNode);
                        index++;
                        //--------SHOULD know if the length will ALWAYS be 4------
                        if (TheTokens.Count == 7 && TheTokens[index] == ";" && CurrToken.statementType != "For_Statement")// && CurrNode.Parent.Text != "Sequence_Of_Statements") // to ensure that there's nothing after the ";"
                            DrawTokensOnTree(TheTokens[EndingIndex], EndingIndex, CurrToken, CurrNode);
                    }
                    else
                    {
                        //ERROR
                        //"new" missing =)
                    }

                }

                else if (TheTokens[index] == ";" && TheTokens.Count == index + 1)
                {
                    DrawTokensOnTree(";", index, CurrToken, CurrNode);
                }
            }
        }
        void ResolveCondition(int StartingIndex, int EndingIndex, int index, List<string> ThisToken, Token CurrToken, TreeNode CurrNode)
        {

            TreeNode TheNode = new TreeNode();
            TheNode = cond(StartingIndex, EndingIndex, ThisToken, CurrToken, CurrNode);
            CurrNode.Nodes.Add(TheNode);
            //string Condition = "";
            //for (int i = StartingIndex; i <= EndingIndex; i++)
            //    Condition += ThisToken[i];
            //DrawTokensOnTree("Condition", index, CurrToken, CurrNode);

            //CurrNode = CurrNode.Parent.Parent;

        }
        void ResolveExpression(int StartingIndex, int EndingIndex, int index, List<string> ThisToken, Token CurrToken, TreeNode CurrNode)
        {
            TreeNode TheNode = new TreeNode();
            TheNode = exp(StartingIndex, EndingIndex, ThisToken, CurrToken, CurrNode);
            //CurrNode.Nodes.Add(TheNode);
            //if(CurrToken.statementType == "For_Statement")
            //    CurrNode.Nodes.Add(TheNode);


            //handah 3ala DrawTokensOnTree ( el EXPRESSION )
            //do ResolveTerms
            //do ResolveFactors
            //-----------------------------------------------------------------------------
            //string Expression = "";
            //for (int i = StartingIndex; i <= EndingIndex; i++)
            //    Expression += ThisToken[i];
            //DrawTokensOnTree("2elExpression", index, CurrToken, CurrNode);
            //-----------------------------------------------------------------------------

            //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            //if (EndingIndex - StartingIndex > 0)// atleast there's one term
            //{
            //    int indexOfAddOp = GetFirstIndexOf(ThisToken, StartingIndex, "+");
            //    int indexOfMulOp = GetFirstIndexOf(ThisToken, StartingIndex, "*");
            //    if (indexOfAddOp != -1 && EndingIndex != indexOfAddOp)// not "x +" => "x + y"
            //    {
            //        CurrNode = CurrNode.Nodes.Add("Term");
            //        CurrNode = CurrNode.Parent;
            //        CurrNode = CurrNode.Nodes.Add("Operator");
            //        CurrNode = CurrNode.Parent;
            //        CurrNode = CurrNode.Nodes.Add("Term");
            //        CurrNode = CurrNode.Parent;


            //    }

            //}
            //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



        }

        //======================+++++++++++++++++++++++++++++=========================
        //======================+++++++++++++++++++++++++++++=========================
        //======================+++++++++++++++++++++++++++++=========================

        private TreeNode exp(int index, int EndingIndex, List<string> TheToken, Token CurrToken, TreeNode CurrNode)
        {
            TreeNode temp = new TreeNode("Expression");

            CurrNode.Nodes.Add(simple_exp(index, EndingIndex, TheToken, CurrToken, CurrNode));
            //if (StringSeparatorContained(TheToken[index], m_DoubleConditionOperatorsBwExp) != "")
            //{
            //    CurrNode.Nodes.Add(TheToken[index]);
            //    index++;
            //    CurrNode.Nodes.Add(simple_exp(index, EndingIndex, TheToken, CurrToken, CurrNode));
            //}
            return temp;
        }
        private TreeNode cond(int index, int EndingIndex, List<string> TheToken, Token CurrToken, TreeNode CurrNode)
        {
            TreeNode temp = new TreeNode("Condition");

            temp.Nodes.Add(simple_cond(index, EndingIndex, TheToken, CurrToken, CurrNode));
            //index++;
            //if (StringSeparatorContained(TheToken[index], m_DoubleConditionOperatorsBwExp) != "" || StringSeparatorContained(TheToken[index], m_SingleConditionOperatorsBwExp) != "")
            //{
            //    TreeNode TheOperator = new TreeNode("Operator");
            //    TheOperator.Nodes.Add(TheToken[index]);
            //    CurrNode.Nodes.Add(TheOperator);
            //    index++;
            //    CurrNode.Nodes.Add(simple_exp(index, EndingIndex, TheToken, CurrToken, CurrNode));
            //}
            //CurrNode = CurrNode.Parent.Parent;
            return temp;
        }
        private TreeNode simple_cond(int index, int EndingIndex, List<string> TheToken, Token CurrToken, TreeNode CurrNode)
        {
            int InternalIndex = index;
            Stack Brackets = new Stack();
            TreeNode temp = new TreeNode("Simple_Condition");
            int TermStartingIndex = index;
            int TermEndingIndex = EndingIndex;
            //DrawTokensOnTree(TheToken[index], index, CurrToken, CurrNode); WRONG
            int index1, index2, indexOfBrackets, firstIndex;
            //index2 = -1;
            indexOfBrackets = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "(");
            index1 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "||");
            index2 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "&&");

            //index1 = GetFirstIndexOfStrArrLimited(TheToken, InternalIndex, EndingIndex, m_DoubleConditionOperatorsBwExp);

            firstIndex = GetTheFirstOccuringIndex(index1, index2, indexOfBrackets);
            if (firstIndex == index1 && index1 != -1)
            {
                TermEndingIndex = index1 - 1;
                //temp.Nodes.Add(conditionTerm(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                InternalIndex = TermEndingIndex;
            }
            else if (firstIndex == index2 && index2 != -1)
            {
                TermEndingIndex = index2 - 1;
                //temp.Nodes.Add(conditionTerm(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                InternalIndex = TermEndingIndex;
            }
            else if (firstIndex == indexOfBrackets && indexOfBrackets != -1)
            {
                TermEndingIndex = DealWithTheBrackets(firstIndex + 1, EndingIndex, indexOfBrackets, TheToken, "conditionTerm");
                InternalIndex = TermEndingIndex;
                //temp.Nodes.Add(conditionTerm(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
            }
            //else if (TermStartingIndex == EndingIndex || firstIndex == -1) //one item OR there's no "+" / "-" / "("
            //{
            //    temp.Nodes.Add(conditionTerm(TermStartingIndex, EndingIndex, TheToken, CurrentToken, CurrNode));
            //    return temp;
            //}
            else
            {
                //ERROR
            }
            InternalIndex = TermEndingIndex;
            InternalIndex++;
            temp.Nodes.Add(conditionTerm(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
            while (InternalIndex < EndingIndex && (TheToken[InternalIndex] == "||" || TheToken[InternalIndex] == "&&"))
            {
                TreeNode Operator = new TreeNode("ConditionOperator");
                Operator.Nodes.Add(TheToken[InternalIndex]);
                temp.Nodes.Add(Operator);
                InternalIndex++;
                TermStartingIndex = InternalIndex;
                TermEndingIndex = EndingIndex;

                indexOfBrackets = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "(");
                index1 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "||");
                index2 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "&&");
                //InternalIndex++;

                firstIndex = GetTheFirstOccuringIndex(index1, index2, indexOfBrackets);
                if (firstIndex == index1 && index1 != -1)
                {
                    TermEndingIndex = index1 - 1;
                    //temp.Nodes.Add(conditionTerm(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                    InternalIndex = TermEndingIndex;
                }
                else if (firstIndex == index2 && index2 != -1)
                {
                    TermEndingIndex = index2 - 1;
                    //temp.Nodes.Add(conditionTerm(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                    InternalIndex = TermEndingIndex;
                }
                else if (firstIndex == indexOfBrackets && indexOfBrackets != -1)
                {
                    TermEndingIndex = DealWithTheBrackets(firstIndex + 1, EndingIndex, indexOfBrackets, TheToken, "conditionTerm");
                    //temp.Nodes.Add(conditionTerm(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                    InternalIndex = TermEndingIndex;
                }
                //else if (InternalIndex == EndingIndex || firstIndex == -1) //one item OR there's no "+" / "-" / "("
                //{
                //    temp.Nodes.Add(conditionTerm(TermStartingIndex, EndingIndex, TheToken, CurrentToken, CurrNode));
                //    return temp;
                //}
                else
                {
                    //ERROR
                }
                temp.Nodes.Add(conditionTerm(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                InternalIndex++;
            }
            return temp;
        }
        private TreeNode conditionTerm(int index, int EndingIndex, List<string> TheToken, Token CurrToken, TreeNode CurrNode)
        {
            int InternalIndex = index;
            //bool FirstTermHasBrackets = false;
            Stack Brackets = new Stack();
            //string TheBracket = "(";
            TreeNode temp = new TreeNode("ConditionTerm");
            int TermStartingIndex = index;
            int TermEndingIndex = EndingIndex;
            //DrawTokensOnTree(TheToken[index], index, CurrToken, CurrNode); WRONG
            int index1, index2, indexOfBrackets, firstIndex;

            indexOfBrackets = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "(");
            //index1 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "*");
            //index2 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "/");

            index1 = GetFirstIndexOfStrArrLimited(TheToken, InternalIndex, EndingIndex, m_ConditionOperators);
            index2 = -1;

            firstIndex = GetTheFirstOccuringIndex(index1, index2, indexOfBrackets);
            if (firstIndex == index1 && index1 != -1)
            {
                TermEndingIndex = index1 - 1;
                //temp.Nodes.Add(conditionFactor(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                InternalIndex = TermEndingIndex;
            }
            else if (firstIndex == index2 && index2 != -1)
            {
                TermEndingIndex = index2 - 1;
                //temp.Nodes.Add(conditionFactor(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                InternalIndex = TermEndingIndex;
            }
            else if (firstIndex == indexOfBrackets && indexOfBrackets != -1)
            {
                TermEndingIndex = DealWithTheBrackets(firstIndex + 1, EndingIndex, indexOfBrackets, TheToken, "conditionFactor");
                InternalIndex = TermEndingIndex;
                //temp.Nodes.Add(conditionFactor(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
            }
            //else if (TermStartingIndex == EndingIndex || firstIndex == -1) //one item OR there's no "+" / "-" / "("
            //{
            //    temp.Nodes.Add(conditionFactor(TermStartingIndex, EndingIndex, TheToken, CurrentToken, CurrNode));
            //    return temp;
            //}
            else
            {
                //ERROR
            }
            InternalIndex = TermEndingIndex;
            InternalIndex++;
            temp.Nodes.Add(conditionFactor(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
            if (InternalIndex < EndingIndex && CheckIfStringEqualsStrArr(m_ConditionOperators, TheToken[InternalIndex]))
            {
                TreeNode Operator = new TreeNode("ConditionOperator");
                Operator.Nodes.Add(TheToken[InternalIndex]);
                temp.Nodes.Add(Operator);
                InternalIndex++;
                TermStartingIndex = InternalIndex;
                TermEndingIndex = EndingIndex;

                indexOfBrackets = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "(");
                //index1 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "*");
                //index2 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "/");

                index1 = GetFirstIndexOfStrArrLimited(TheToken, InternalIndex, EndingIndex, m_ConditionOperators);
                index2 = -1;

                firstIndex = GetTheFirstOccuringIndex(index1, index2, indexOfBrackets);
                if (firstIndex == index1 && index1 != -1)
                {
                    TermEndingIndex = index1 - 1;
                    //temp.Nodes.Add(conditionFactor(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                    InternalIndex = TermEndingIndex;
                }
                else if (firstIndex == index2 && index2 != -1)
                {
                    TermEndingIndex = index2 - 1;
                    //temp.Nodes.Add(conditionFactor(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                    InternalIndex = TermEndingIndex;
                }
                else if (firstIndex == indexOfBrackets && indexOfBrackets != -1)
                {
                    TermEndingIndex = DealWithTheBrackets(firstIndex + 1, EndingIndex, indexOfBrackets, TheToken, "factor");
                    //temp.Nodes.Add(conditionFactor(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                    InternalIndex = TermEndingIndex;
                }
                //else if (InternalIndex == EndingIndex || firstIndex == -1) //one item OR there's no "+" / "-" / "("
                //{
                //    temp.Nodes.Add(conditionFactor(TermStartingIndex, EndingIndex, TheToken, CurrentToken, CurrNode));
                //    return temp;
                //}
                else
                {
                    //ERROR
                }
                InternalIndex++;
                temp.Nodes.Add(conditionFactor(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
            }
            return temp;
        }
        private TreeNode conditionFactor(int index, int EndingIndex, List<string> TheToken, Token CurrToken, TreeNode CurrNode)
        {
            TreeNode temp = new TreeNode("ConditionFactor");
            if (TheToken[index] == "(")
            {
                //temp.Nodes.Add(new TreeNode(TheToken[index]));
                index++;
                EndingIndex = GetLastIndexOfLimited(TheToken, index, EndingIndex, ")");
                temp.Nodes.Add(simple_cond(index, EndingIndex - 1, TheToken, CurrToken, CurrNode));
                index = EndingIndex;

                if (TheToken[index] == ")")
                {
                    //temp.Nodes.Add(new TreeNode(TheToken[index]));
                }
            }
            else
                temp.Nodes.Add(simple_exp(index, EndingIndex, TheToken, CurrToken, CurrNode));
            //if (m_IntegerConstants.IsMatch(TheToken[index]))
            //{
            //    TreeNode tempType = new TreeNode("Constant");
            //    temp.Nodes.Add(tempType);
            //    tempType.Nodes.Add(new TreeNode(TheToken[index]));
            //    index++;
            //}
            //else
            //    if (IfStackContains(m_DeclaredIntegersArray, TheToken[index]) || IfStackContains(m_DeclaredIntegers, TheToken[index]) || IfStackContains(m_DeclaredHashtables, TheToken[index]) || IfStackContains(m_DeclaredCharacters, TheToken[index]) || IfStackContains(m_DeclaredCharacterArray, TheToken[index]))
            //    {
            //        TreeNode tempType = new TreeNode("Identifier");
            //        temp.Nodes.Add(tempType);
            //        tempType.Nodes.Add(new TreeNode(TheToken[index]));
            //        index++;
            //    }
            //    else
            //        if (TheToken[index] == "(")
            //        {
            //            temp.Nodes.Add(new TreeNode(TheToken[index]));
            //            index++;
            //            EndingIndex = GetLastIndexOfLimited(TheToken, index, EndingIndex, ")");
            //            temp.Nodes.Add(simple_exp(index, EndingIndex - 1, TheToken, CurrToken, CurrNode));
            //            index = EndingIndex;

            //            if (TheToken[index] == ")")
            //                temp.Nodes.Add(new TreeNode(TheToken[index]));
            //        }
            return temp;
        }
        int GetTheFirstOccuringIndex(int index1, int index2, int index3)
        {
            if (index1 != -1 && (index1 < index2 || index2 == -1) && (index1 < index3 || index3 == -1))
                return index1;
            else if (index2 != -1 && (index2 < index1 || index1 == -1) && (index2 < index3 || index3 == -1))
                return index2;
            else if (index3 != -1 && (index3 < index1 || index1 == -1) && (index3 < index2 || index2 == -1))
                return index3;
            return -1;
        }
        int DealWithTheBrackets(int Start, int End, int IndexOFCurrentBracket, List<string> TheToken, string TermOrFactor)
        {
            int PreviousOpBracket = Start;
            int PreviousClBracket = Start;
            int InternalIndex = Start;
            string TheBracket = "(";
            Stack Brackets = new Stack();
            Brackets.Push((object)TheBracket);
            int index1, index2;
            while (Brackets.Count > 0)
            {
                index1 = GetFirstIndexOfLimited(TheToken, PreviousOpBracket, End, "(");
                index2 = GetFirstIndexOfLimited(TheToken, PreviousClBracket, End, ")");
                if (index1 < index2 && index1 != -1)
                {
                    Brackets.Push((object)TheBracket);
                    InternalIndex = index1;
                    PreviousOpBracket = InternalIndex + 1;
                    PreviousClBracket = PreviousOpBracket;
                }
                else if ((index2 < index1 && index2 != -1) || (index1 == -1 && index2 != -1))
                {
                    Brackets.Pop();
                    InternalIndex = index2;
                    PreviousClBracket = InternalIndex + 1;
                    PreviousOpBracket = PreviousClBracket;
                }
                else
                {
                    //ERROR probably missing bracket.
                }
            }
            InternalIndex = AfterBrackets(InternalIndex, End, TheToken, TermOrFactor);
            return InternalIndex;
        }
        int AfterBrackets(int start, int end, List<string> TheToken, string TermOrFactor)
        {
            int InternalIndex = start;
            int index1 = 0;
            int index2 = 0;
            int indexOfBrackets, firstIndex;
            int EndingAfterBrackets = start;
            while (InternalIndex < end)
            {
                indexOfBrackets = GetFirstIndexOfLimited(TheToken, InternalIndex, end, "(");
                if (TermOrFactor == "term")
                {
                    index1 = GetFirstIndexOfLimited(TheToken, InternalIndex, end, "+");
                    index2 = GetFirstIndexOfLimited(TheToken, InternalIndex, end, "-");
                }
                else if (TermOrFactor == "factor")
                {
                    index1 = GetFirstIndexOfLimited(TheToken, InternalIndex, end, "*");
                    index2 = GetFirstIndexOfLimited(TheToken, InternalIndex, end, "/");
                }
                else if (TermOrFactor == "conditionTerm")
                {
                    index1 = GetFirstIndexOfLimited(TheToken, InternalIndex, end, "||");
                    index2 = GetFirstIndexOfLimited(TheToken, InternalIndex, end, "&&");
                }
                else if (TermOrFactor == "conditionFactor")
                {
                    //index1 = GetFirstIndexOfLimited(TheToken, InternalIndex, end, "||");
                    index1 = GetFirstIndexOfStrArrLimited(TheToken, InternalIndex, end, m_DoubleConditionOperatorsBwExp);
                    index2 = -1;
                }
                firstIndex = GetTheFirstOccuringIndex(index1, index2, indexOfBrackets);
                if (firstIndex == index1 && index1 != -1)
                {
                    EndingAfterBrackets = index1 - 1;
                    return EndingAfterBrackets;
                }
                else if (firstIndex == index2 && index2 != -1)
                {
                    EndingAfterBrackets = index2 - 1;
                    return EndingAfterBrackets;
                }
                else if (firstIndex == indexOfBrackets && indexOfBrackets != -1)
                {
                    InternalIndex = DealWithTheBrackets(firstIndex + 1, end, indexOfBrackets, TheToken, TermOrFactor);
                }
                else if (InternalIndex == end || firstIndex == -1) //one item OR there's no "+" / "-" / "("
                {
                    return end;
                }
                else
                {
                    //ERROR
                }
            }
            return InternalIndex;
        }
        int AfterARRAYBrackets(int start, int end, List<string> TheToken, string TermOrFactor, string Operator)
        {
            int InternalIndex = start;
            int index1 = 0;
            int index2 = 0;
            int indexOfBrackets, firstIndex;
            int EndingAfterBrackets = start;
            while (InternalIndex < end)
            {
                indexOfBrackets = GetFirstIndexOfLimited(TheToken, InternalIndex, end, "[");
                if (TermOrFactor == "term")
                {
                    index1 = GetFirstIndexOfLimited(TheToken, InternalIndex, end, Operator);
                    //index2 = GetFirstIndexOfLimited(TheToken, InternalIndex, end, "-");
                    index2 = -1;
                }
                else if (TermOrFactor == "factor")
                {
                    index1 = GetFirstIndexOfLimited(TheToken, InternalIndex, end, Operator);
                    //index2 = GetFirstIndexOfLimited(TheToken, InternalIndex, end, "/");
                    index2 = -1;
                }
                firstIndex = GetTheFirstOccuringIndex(index1, index2, indexOfBrackets);
                if (firstIndex == index1 && index1 != -1)
                {
                    EndingAfterBrackets = index1;
                    return EndingAfterBrackets;
                }
                else if (firstIndex == index2 && index2 != -1)
                {
                    EndingAfterBrackets = index2;
                    return EndingAfterBrackets;
                }
                else if (firstIndex == indexOfBrackets && indexOfBrackets != -1)
                {
                    InternalIndex = NewTermOrFactorIndexAfterArrayBrackets(TheToken, firstIndex + 1, end, index1, indexOfBrackets, TermOrFactor, Operator);
                }
                else if (InternalIndex == end || firstIndex == -1) //one item OR there's no "+" / "-" / "("
                {
                    return end;
                }
                else
                {
                    //ERROR
                }
            }
            return -1;
        }
        int NewTermOrFactorIndexAfterArrayBrackets(List<string> TheToken, int BegingIndex, int EndIndex, int CurrentOperatorIndex, int FirstArrOpeningBracketIndex, string TermOrFactor, string Operator)
        {
            if (FirstArrOpeningBracketIndex != -1 && FirstArrOpeningBracketIndex < CurrentOperatorIndex)
            {
                int PreviousOpBracket = FirstArrOpeningBracketIndex + 1;
                int PreviousClBracket = FirstArrOpeningBracketIndex + 1;
                int InternalIndex = FirstArrOpeningBracketIndex;
                string TheBracket = "[";
                Stack Brackets = new Stack();
                Brackets.Push((object)TheBracket);
                int index1, index2;
                while (Brackets.Count > 0)
                {
                    index1 = GetFirstIndexOfLimited(TheToken, PreviousOpBracket, EndIndex, "[");
                    index2 = GetFirstIndexOfLimited(TheToken, PreviousClBracket, EndIndex, "]");
                    if (index1 < index2 && index1 != -1)
                    {
                        Brackets.Push((object)TheBracket);
                        InternalIndex = index1;
                        PreviousOpBracket = InternalIndex + 1;
                        PreviousClBracket = PreviousOpBracket;
                    }
                    else if ((index2 < index1 && index2 != -1) || (index1 == -1 && index2 != -1))
                    {
                        Brackets.Pop();
                        InternalIndex = index2;
                        PreviousClBracket = InternalIndex + 1;
                        PreviousOpBracket = PreviousClBracket;
                    }
                    else
                    {
                        //ERROR probably missing bracket.
                    }
                }
                InternalIndex = AfterARRAYBrackets(InternalIndex, EndIndex, TheToken, TermOrFactor, Operator);
                return InternalIndex;
            }
            //else
            //    return CurrentOperatorIndex;
            return CurrentOperatorIndex;// 3ashan maybo22esh ma3aya
        }
        private TreeNode simple_exp(int index, int EndingIndex, List<string> TheToken, Token CurrToken, TreeNode CurrNode)
        {
            int InternalIndex = index;
            Stack Brackets = new Stack();
            TreeNode temp = new TreeNode("Simple_Expression");
            int TermStartingIndex = index;
            int TermEndingIndex = EndingIndex;
            //DrawTokensOnTree(TheToken[index], index, CurrToken, CurrNode); WRONG
            int index1, index2, indexOfBrackets, firstIndex, arrBracket1;

            indexOfBrackets = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "(");
            index1 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "+");
            index2 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "-");

            arrBracket1 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "[");

            index1 = NewTermOrFactorIndexAfterArrayBrackets(TheToken, InternalIndex, EndingIndex, index1, arrBracket1, "term", "+");
            index2 = NewTermOrFactorIndexAfterArrayBrackets(TheToken, InternalIndex, EndingIndex, index2, arrBracket1, "term", "-");

            firstIndex = GetTheFirstOccuringIndex(index1, index2, indexOfBrackets);
            if (firstIndex == index1 && index1 != -1)
            {
                TermEndingIndex = index1 - 1;
                //temp.Nodes.Add(term(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                InternalIndex = TermEndingIndex;
            }
            else if (firstIndex == index2 && index2 != -1)
            {
                TermEndingIndex = index2 - 1;
                //temp.Nodes.Add(term(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                InternalIndex = TermEndingIndex;
            }
            else if (firstIndex == indexOfBrackets && indexOfBrackets != -1 && ((indexOfBrackets < arrBracket1 && arrBracket1 != -1) || arrBracket1 == -1))
            {
                TermEndingIndex = DealWithTheBrackets(firstIndex + 1, EndingIndex, indexOfBrackets, TheToken, "term");
                InternalIndex = TermEndingIndex;
                //temp.Nodes.Add(term(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
            }
            else if (TermStartingIndex == EndingIndex || firstIndex == -1) //one item OR there's no "+" / "-" / "("
            {
                temp.Nodes.Add(term(TermStartingIndex, EndingIndex, TheToken, CurrentToken, CurrNode));
                return temp;
            }
            else
            {
                //ERROR
            }
            InternalIndex = TermEndingIndex;
            InternalIndex++;
            temp.Nodes.Add(term(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
            while (InternalIndex < EndingIndex && (TheToken[InternalIndex] == "+" || TheToken[InternalIndex] == "-"))
            {
                TreeNode Operator = new TreeNode("Operator");
                Operator.Nodes.Add(TheToken[InternalIndex]);
                temp.Nodes.Add(Operator);
                InternalIndex++;
                TermStartingIndex = InternalIndex;
                TermEndingIndex = EndingIndex;

                indexOfBrackets = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "(");
                index1 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "+");
                index2 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "-");
                //InternalIndex++;

                arrBracket1 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "[");

                index1 = NewTermOrFactorIndexAfterArrayBrackets(TheToken, InternalIndex, EndingIndex, index1, arrBracket1, "term", "+");
                index2 = NewTermOrFactorIndexAfterArrayBrackets(TheToken, InternalIndex, EndingIndex, index2, arrBracket1, "term", "-");

                firstIndex = GetTheFirstOccuringIndex(index1, index2, indexOfBrackets);
                if (firstIndex == index1 && index1 != -1)
                {
                    TermEndingIndex = index1 - 1;
                    //temp.Nodes.Add(term(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                    InternalIndex = TermEndingIndex;
                }
                else if (firstIndex == index2 && index2 != -1)
                {
                    TermEndingIndex = index2 - 1;
                    //temp.Nodes.Add(term(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                    InternalIndex = TermEndingIndex;
                }
                else if (firstIndex == indexOfBrackets && indexOfBrackets != -1 && ((indexOfBrackets < arrBracket1 && arrBracket1 != -1) || arrBracket1 == -1))
                {
                    TermEndingIndex = DealWithTheBrackets(firstIndex + 1, EndingIndex, indexOfBrackets, TheToken, "term");
                    //temp.Nodes.Add(term(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                    InternalIndex = TermEndingIndex;
                }
                else if (InternalIndex == EndingIndex || firstIndex == -1) //one item OR there's no "+" / "-" / "("
                {
                    temp.Nodes.Add(term(TermStartingIndex, EndingIndex, TheToken, CurrentToken, CurrNode));
                    return temp;
                }
                else
                {
                    //ERROR
                }
                temp.Nodes.Add(term(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                InternalIndex++;
            }
            return temp;
        }
        private TreeNode term(int index, int EndingIndex, List<string> TheToken, Token CurrToken, TreeNode CurrNode)
        {
            int InternalIndex = index;
            //bool FirstTermHasBrackets = false;
            Stack Brackets = new Stack();
            //string TheBracket = "(";
            TreeNode temp = new TreeNode("Term");
            int TermStartingIndex = index;
            int TermEndingIndex = EndingIndex;
            //DrawTokensOnTree(TheToken[index], index, CurrToken, CurrNode); WRONG
            int index1, index2, indexOfBrackets, firstIndex, arrBracket1;

            indexOfBrackets = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "(");
            index1 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "*");
            index2 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "/");

            arrBracket1 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "[");

            index1 = NewTermOrFactorIndexAfterArrayBrackets(TheToken, InternalIndex, EndingIndex, index1, arrBracket1, "factor", "*");
            index2 = NewTermOrFactorIndexAfterArrayBrackets(TheToken, InternalIndex, EndingIndex, index2, arrBracket1, "factor", "/");

            firstIndex = GetTheFirstOccuringIndex(index1, index2, indexOfBrackets);
            if (firstIndex == index1 && index1 != -1)
            {
                TermEndingIndex = index1 - 1;
                //temp.Nodes.Add(term(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                InternalIndex = TermEndingIndex;
            }
            else if (firstIndex == index2 && index2 != -1)
            {
                TermEndingIndex = index2 - 1;
                //temp.Nodes.Add(term(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                InternalIndex = TermEndingIndex;
            }
            else if (firstIndex == indexOfBrackets && indexOfBrackets != -1 && ((indexOfBrackets < arrBracket1 && arrBracket1 != -1) || arrBracket1 == -1))
            {
                TermEndingIndex = DealWithTheBrackets(firstIndex + 1, EndingIndex, indexOfBrackets, TheToken, "factor");
                InternalIndex = TermEndingIndex;
                //temp.Nodes.Add(term(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
            }
            else if (TermStartingIndex == EndingIndex || firstIndex == -1) //one item OR there's no "+" / "-" / "("
            {
                temp.Nodes.Add(factor(TermStartingIndex, EndingIndex, TheToken, CurrentToken, CurrNode));
                return temp;
            }
            else
            {
                //ERROR
            }
            InternalIndex = TermEndingIndex;
            InternalIndex++;
            temp.Nodes.Add(factor(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
            while (InternalIndex < EndingIndex && (TheToken[InternalIndex] == "*" || TheToken[InternalIndex] == "/"))
            {
                TreeNode Operator = new TreeNode("Operator");
                Operator.Nodes.Add(TheToken[InternalIndex]);
                temp.Nodes.Add(Operator);
                InternalIndex++;
                TermStartingIndex = InternalIndex;
                TermEndingIndex = EndingIndex;

                indexOfBrackets = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "(");
                index1 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "*");
                index2 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "/");


                arrBracket1 = GetFirstIndexOfLimited(TheToken, InternalIndex, EndingIndex, "[");

                index1 = NewTermOrFactorIndexAfterArrayBrackets(TheToken, InternalIndex, EndingIndex, index1, arrBracket1, "factor", "*");
                index2 = NewTermOrFactorIndexAfterArrayBrackets(TheToken, InternalIndex, EndingIndex, index2, arrBracket1, "factor", "/");

                firstIndex = GetTheFirstOccuringIndex(index1, index2, indexOfBrackets);
                if (firstIndex == index1 && index1 != -1)
                {
                    TermEndingIndex = index1 - 1;
                    //temp.Nodes.Add(factor(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                    InternalIndex = TermEndingIndex;
                }
                else if (firstIndex == index2 && index2 != -1)
                {
                    TermEndingIndex = index2 - 1;
                    //temp.Nodes.Add(factor(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                    InternalIndex = TermEndingIndex;
                }
                else if (firstIndex == indexOfBrackets && indexOfBrackets != -1 && ((indexOfBrackets < arrBracket1 && arrBracket1 != -1) || arrBracket1 == -1))
                {
                    TermEndingIndex = DealWithTheBrackets(firstIndex + 1, EndingIndex, indexOfBrackets, TheToken, "factor");
                    //temp.Nodes.Add(factor(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
                    InternalIndex = TermEndingIndex;
                }
                else if (InternalIndex == EndingIndex || firstIndex == -1) //one item OR there's no "+" / "-" / "("
                {
                    temp.Nodes.Add(factor(TermStartingIndex, EndingIndex, TheToken, CurrentToken, CurrNode));
                    return temp;
                }
                else
                {
                    //ERROR
                }
                InternalIndex++;
                temp.Nodes.Add(factor(TermStartingIndex, TermEndingIndex, TheToken, CurrentToken, CurrNode));
            }
            return temp;
        }
        private TreeNode factor(int index, int EndingIndex, List<string> TheToken, Token CurrToken, TreeNode CurrNode)
        {
            TreeNode temp = new TreeNode("Factor");
            if ((m_IntegerConstants.IsMatch(TheToken[index]) || m_CharacterConstants.IsMatch(TheToken[index])) && !IfStackContains(m_DeclaredIntegersArray, TheToken[index]) && !IfStackContains(m_DeclaredCharacterArray, TheToken[index]) && !IfStackContains(m_DeclaredIntegers, TheToken[index]) && !IfStackContains(m_DeclaredCharacters, TheToken[index]) && !IfStackContains(m_DeclaredHashtables, TheToken[index]))
            {
                TreeNode tempType = new TreeNode("Constant");
                temp.Nodes.Add(tempType);
                tempType.Nodes.Add(new TreeNode(TheToken[index]));
                index++;
            }
            else if (IfStackContains(m_DeclaredIntegers, TheToken[index]) || IfStackContains(m_DeclaredCharacters, TheToken[index]))
            {
                TreeNode tempType = new TreeNode("Identifier");
                temp.Nodes.Add(tempType);
                tempType.Nodes.Add(new TreeNode(TheToken[index]));
                index++;
            }
            else if (IfStackContains(m_DeclaredIntegersArray, TheToken[index]) || IfStackContains(m_DeclaredCharacterArray, TheToken[index]))
            {
                TreeNode tempType = new TreeNode("Identifier");
                temp.Nodes.Add(tempType);
                tempType.Nodes.Add(new TreeNode(TheToken[index]));
                index++;
                if (TheToken[index] == "[")
                {
                    TreeNode op = new TreeNode("Operator");
                    op.Nodes.Add(TheToken[index]);
                    temp.Nodes.Add(op);
                    index++;
                    int initialExpIndex = index;
                    int finalExpIndex = index;
                    int PreviousOpBracket = index;
                    int PreviousClBracket = index;
                    string TheBracket = "[";
                    Stack Brackets = new Stack();
                    Brackets.Push((object)TheBracket);
                    int index1 = -1;
                    int index2 = -1;
                    //for (int i = index; i < TheToken.Count; i++)
                    //{
                    //    if (TheToken[i] == "]")
                    //    {
                    //        finalExpIndex = i;
                    //        break;
                    //    }
                    //}
                    while (Brackets.Count > 0)
                    {
                        index1 = GetFirstIndexOfLimited(TheToken, PreviousOpBracket, EndingIndex, "[");
                        index2 = GetFirstIndexOfLimited(TheToken, PreviousClBracket, EndingIndex, "]");
                        if (index1 < index2 && index1 != -1)
                        {
                            Brackets.Push((object)TheBracket);
                            finalExpIndex = index1;
                            PreviousOpBracket = finalExpIndex + 1;
                            PreviousClBracket = PreviousOpBracket;
                        }
                        else if ((index2 < index1 && index2 != -1) || (index1 == -1 && index2 != -1))
                        {
                            Brackets.Pop();
                            finalExpIndex = index2;
                            PreviousClBracket = finalExpIndex + 1;
                            PreviousOpBracket = PreviousClBracket;
                        }
                        else
                        {
                            //ERROR probably missing bracket.
                        }
                    }
                    tempType = new TreeNode("Expression");
                    tempType.Nodes.Add(simple_exp(initialExpIndex, finalExpIndex - 1, TheToken, CurrToken, tempType));
                    temp.Nodes.Add(tempType);
                    TreeNode op1 = new TreeNode("Operator");
                    op1.Nodes.Add(TheToken[finalExpIndex]);
                    temp.Nodes.Add(op1);
                }
                else
                {
                    //ERROR
                }
                index++;
            }
            else
                if (TheToken[index] == "(")
                {
                    //temp.Nodes.Add(new TreeNode(TheToken[index]));
                    index++;
                    EndingIndex = GetLastIndexOfLimited(TheToken, index, EndingIndex, ")");
                    temp.Nodes.Add(simple_exp(index, EndingIndex - 1, TheToken, CurrToken, CurrNode));
                    index = EndingIndex;

                    if (TheToken[index] == ")")
                    {
                        //temp.Nodes.Add(new TreeNode(TheToken[index]));
                    }
                }
            return temp;
        }
        //======================+++++++++++++++++++++++++++++=========================
        //======================+++++++++++++++++++++++++++++=========================
        //======================+++++++++++++++++++++++++++++=========================
        int GetLastIndexOfLimited(List<string> StringArr, int StartingIndex, int EndingIndex, string item)
        {
            for (int i = EndingIndex; i >= StartingIndex; i--)
                if (StringArr[i] == item)
                    return i;
            return -1;
        }
        void DrawTokensOnTree(string ThisStringToken, int index, Token CurrToken, TreeNode CurrNode)
        {
            TreeNode ThisTempNode;
            Token ThisToken;
            ThisToken = new Token(ThisStringToken, index);
            ThisToken.statementType = CurrToken.statementType;
            ThisTempNode = CurrNode.Nodes.Add(ThisToken.tokenType);
            ThisTempNode.Nodes.Add(ThisStringToken);
        }
        int GetFirstIndexOf(List<string> StringArr, int StartingIndex, string item)
        {
            for (int i = StartingIndex; i < StringArr.Count; i++)
                if (StringArr[i] == item)
                    return i;
            return -1;
        }
        int GetFirstIndexOfStrArrLimited(List<string> StringArr, int StartingIndex, int EndingIndex, List<string> items)
        {
            for (int i = StartingIndex; i <= EndingIndex; i++)
            {
                for (int j = 0; j < items.Count; j++)
                    if (StringArr[i] == items[j])
                        return i;
            }
            return -1;
        }
        int GetFirstIndexOfLimited(List<string> StringArr, int StartingIndex, int EndingIndex, string item)
        {
            for (int i = StartingIndex; i <= EndingIndex; i++)
                if (StringArr[i] == item)
                    return i;
            return -1;
        }
        int GetNumberOfOccurences(List<string> StringArr, string item)
        {
            int counter = 0;
            for (int i = 0; i < StringArr.Count; i++)
                if (StringArr[i] == item)
                    counter++;
            return counter;
        }
        bool CheckIfStringEqualsStrArr(List<string> StringArr, string item)
        {
            for (int i = 0; i < StringArr.Count; i++)
            {
                if (StringArr[i] == item)
                    return true;
            }
            return false;
        }
    }
}